API Reference
codeExecutionTool
function codeExecutionTool(backend): Tool;Defined in: tools/builtin/code-execution.ts:43
Build a code_execution tool bound to a backend.
Parameters
| Parameter | Type | Description |
|---|---|---|
backend | CodeExecutionBackend | The CodeExecutionBackend that actually runs code in a sandbox. |
Returns
A Tool named code_execution ready to pass to the agent loop or a ToolRegistry.
Remarks
Runs sequentially (ExecutionMode.Sequential): model-written code
commonly has side effects and often shares a workspace, so the loop must not
race a batch of snippets against each other — the same reasoning as
shellTool. The language is an open string: the contract stays stable
across backends, and each backend rejects what it cannot run. Results are
shaped by formatCodeExecutionResult.
See
- CodeExecutionBackend
- shellTool — its single-command sibling.
Example
const tool = codeExecutionTool(denoCodeExecutionBackend());
// Recommended: gate code execution before granting it to an untrusted model.
await runAgent({ ...opts, tools: [tool] });
// The model can now call: code_execution({ language: "javascript", code: "console.log(6 * 7)" })