execute_code tool backed by a SandboxRuntime interface. The LLM writes a short self-contained script, passes it to the tool, and reads the actual output. The sandbox handles isolation — the SDK never runs code itself.
What the LLM does vs. what the sandbox does
The LLM never invents output — it always calls
execute_code first.
Example: Code Execution.
Tool pattern
Execute blocks until the sandbox returns ExecutionResult{Output, ExitCode}. The LLM reads output from the result and replies to the user.
Sandbox options
ImplementSandboxRuntime once per environment. The example ships two; add more by following the same pattern:
Only
main.go changes when you swap runtimes — code_tool.go and the agent config stay the same.
Docker sandbox isolation
The example Docker runner passes safety flags todocker run:
--cpus, --read-only, and a non-root user.
Timeout layers
System prompt guidance
Tell the LLM not to make up output — it must call the tool first:Examples
Code Execution
execute_code tool with local and Docker runtimes
Execution config
Per-operation timeout overrides
Related
Execution config
Tool execute timeout and max attempts
Deterministic Execution
Running predefined workflows from the agent
Tools
Custom tool implementation