Skip to main content
Glama

Execute C# in Editor (sandboxed)

unity_execute_code
Destructive

Compile and run bare C# statements in the Unity Editor via Roslyn. Returns a job_id to poll for results, enabling scripted editor automation and self-play hooks.

Instructions

Compile and run bare C# statements inside the Unity Editor via Roslyn/AssemblyBuilder. Returns a job_id immediately — poll unity_get_code_result for completion (compile takes ~2-10s).

Code rules: bare statements only (wrapped into static Run(); UnityEngine/UnityEditor/System/LINQ usings included); 'return ;' sends JSON back. Keep snippets short and side-effect aware (runs on main thread; infinite loops hang the Editor). Sandbox blocks: filesystem (System.IO/File./Directory.), processes, network, reflection-load (Assembly.Load/Activator/DllImport), Application.Quit, while(true)/for(;;). Requires: mutations ON + 'Enable C# execution' in Window > Unity MCP (off by default).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesBare C# statements executed inside a static Run() (UnityEngine/UnityEditor/System/LINQ usings pre-included). Use 'return <value>;' to send a result back. Example: 'var go = GameObject.Find("Player"); return go.transform.position.ToString();'
timeout_sNoJob timeout in seconds (10-300, default 60)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes far beyond the annotations: enumerates the sandbox blocklist (filesystem, processes, network, reflection-load, Application.Quit, while(true)), warns that it runs on the main thread and infinite loops hang the Editor, and states the opt-in gating. destructiveHint=true is consistent and richly substantiated.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and the polling contract, then cleanly segmented into 'Code rules', 'Sandbox blocks', and 'Requires'. Slightly long and the code rules partly duplicate the schema, but every section carries essential caveats for a sandboxed code tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a high-risk execution tool with no output schema, it covers the async result path, latency, sandbox constraints, thread behavior, and the opt-in prerequisite — everything an agent needs to call it safely and correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both params, including the bare-statement/return semantics for 'code'. The description largely restates those code rules and never mentions timeout_s, so it adds little parameter meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource ('compile and run bare C# statements inside the Unity Editor') and names the execution mechanism (Roslyn/AssemblyBuilder). It is unambiguously the only code-execution sibling among read/set/create/delete tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives the async workflow explicitly ('Returns a job_id immediately — poll unity_get_code_result'), the compile latency, and the hard prerequisite ('Requires: mutations ON + Enable C# execution... off by default'). It doesn't explicitly say when to prefer a dedicated sibling (e.g. unity_set_transform) over writing raw C#, so it stops short of full when-not guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.