execute_code tool. The LLM writes a short script, the sandbox runs it, and the output is returned for the LLM to explain. The sandbox is pluggable — swap the runtime without changing the tool.
Source: examples/agent_with_code_execution/
What it demonstrates
execute_codecustom tool —interfaces.ToolwithlanguageandcodeparametersSandboxRuntimeinterface — pluggable sandbox (local os/exec, Docker, cloud APIs)- LLM writes code, runs it, reads output, replies — never makes up results
- Sandbox isolation — Docker runner uses
--network noneand memory limits
Run
Fromexamples/:
Local sandbox — needs Python or Node installed on host:
LLM_APIKEY in examples/.env.
Key code
Execute blocks until SandboxRuntime.Execute returns the program output and exit code.
Expected output
Learn more
Code Execution in Agents
Sandbox options, isolation, timeout config, cloud runtimes
Execution config
Tool execute timeout and max attempts