Execute Code
execute_codeRun C# code in the Unity Editor directly. Supports code execution, history, replay, and safety checks to prevent harmful operations.
Instructions
Execute arbitrary C# code inside the Unity Editor. The code runs as a method body with access to UnityEngine and UnityEditor namespaces. Use 'return' to send data back. Compiled in-memory — no script files created. Actions: execute (run code), get_history (list past executions), replay (re-run a history entry), clear_history. NOTE: safety_checks blocks known dangerous patterns but is not a full sandbox. Compiler options: 'auto' (Roslyn if available, else CodeDom), 'roslyn' (C# 12+, requires Microsoft.CodeAnalysis), 'codedom' (C# 6 only).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | ||
| index | No | ||
| limit | No | Number of history entries to return (for 'get_history' action, 1-50). Default: 10. | |
| action | Yes | Action to perform. | |
| compiler | No | Compiler backend for 'execute' action. 'auto' uses Roslyn if Microsoft.CodeAnalysis is installed, else falls back to CodeDom. 'roslyn' forces Roslyn (C# 12+). 'codedom' forces legacy CSharpCodeProvider (C# 6). Default: auto. | auto |
| safety_checks | No | Enable basic blocked-pattern checks (File.Delete, Process.Start, infinite loops, etc). Not a full sandbox — advanced bypass is possible. Default: true. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||