Skip to main content

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.
timeout
number
default:"30000"
Execution timeout in milliseconds.
maxOutput
number
default:"10000"
Max output characters to return. Long output is truncated.
cwd
string
Working directory for script execution. Defaults to os.tmpdir().

Tools

ToolDescription
code_runExecute code in a subprocess. Returns stdout, stderr, and exit code.

Language Runtimes

LanguageRuntimeRequirement
JavaScriptnodeAlways available
Pythonpython3Must be in PATH
TypeScriptnpx tsxRequires 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