Open Agent Loops
API Reference

codeExecutionTool

@open-agent-loops/core


function codeExecutionTool(backend): Tool;

Defined in: tools/builtin/code-execution.ts:43

Build a code_execution tool bound to a backend.

Parameters

ParameterTypeDescription
backendCodeExecutionBackendThe CodeExecutionBackend that actually runs code in a sandbox.

Returns

Tool

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

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)" })

On this page