Code Interpreter
Let agents write and execute code (JavaScript, Python, TypeScript) in a subprocess. Essential for data analysis, math, and automation agents.
Quick Start
import { Agent, openai, CodeInterpreterToolkit } from "@radaros/core";
const code = new CodeInterpreterToolkit({
languages: ["javascript", "python"],
timeout: 30_000,
});
const agent = new Agent({
name: "analyst",
model: openai("gpt-4o"),
instructions: "Write and execute code to solve problems. Use Python for data analysis and JavaScript for general tasks.",
tools: [...code.getTools()],
});
const result = await agent.run("Calculate the first 20 Fibonacci numbers and return them as a list.");
Config
languages
('javascript' | 'python' | 'typescript')[]
default:"['javascript', 'python']"
Allowed languages for code execution.
Execution timeout in milliseconds.
Max output characters to return. Long output is truncated.
Working directory for script execution. Defaults to os.tmpdir().
| Tool | Description |
|---|
code_run | Execute code in a subprocess. Returns stdout, stderr, and exit code. |
Language Runtimes
| Language | Runtime | Requirement |
|---|
| JavaScript | node | Always available |
| Python | python3 | Must be in PATH |
| TypeScript | npx tsx | Requires tsx installed |
Code is executed in a subprocess with no sandboxing beyond the OS-level process boundary. Always set timeout and maxOutput to prevent runaway execution.
Example: Data Analysis
const result = await agent.run(`
Read the CSV file at /tmp/sales.csv, calculate the total revenue
per region, and output a summary table.
`);
// Agent writes Python code using pandas, executes it, returns results