Tools · Files and code
run_code
Changes thingsExecute Python or shell code in a local subprocess workspace.
When to use: Use this for deterministic local execution, transformations, parsing, and script-based validation.
Example
Run for real by scripts/tool-examples.py in a small demo project, with Haiku 5.5 where the tool calls a model. The output is exactly what the tool returned.
The call
{
"tool": "run_code",
"arguments": {
"language": "python",
"code": "import statistics\nprices = [12, 29, 79]\nprint('mean', statistics.mean(prices), 'median', statistics.median(prices))"
}
}Real output
exit_code: 0 stdout: mean 40 median 29 stderr:
Parameters
| Name | Type | Description |
|---|---|---|
| language* | string | Interpreter to usebashjavascriptluaperlphppythonrrubyshtypescriptzsh |
| code* | string | Source code to execute |
| timeout_seconds | number | Optional execution timeout |
| sandbox | boolean | Run inside a disposable Docker container with --network none and a read-only rootfs. Safer for untrusted snippets. Requires `docker` on PATH. |
| network | boolean | When sandbox=true, allow outbound network. Default false. |
| image | string | When sandbox=true, override the default Docker image for the chosen language. |
| workspace_root | string | Override the workspace directory for this call. Lets specialists (developer, debugger, designer, researcher) work inside the user's project instead of the shared default. Absolute or cwd-relative path. |
* required
More in Files and code
Read, search and edit the project; run commands, code and git.