Code Interpreter
The run_code
tool enables Letta agents to execute code in a secure sandboxed environment. Useful for data analysis, calculations, API calls, and programmatic computation.
On Letta Cloud, this tool works out of the box. For self-hosted deployments, you’ll need to configure an E2B API key.
Each execution runs in a fresh environment - variables, files, and state do not persist between runs.
Quick Start
Tool Parameters
Return Format
Output types:
results[]
: Last expression value (Jupyter-style)logs.stdout
: Print statements and standard outputlogs.stderr
: Error messageserror
: Present if execution failed
Supported Languages
Python
Full Python ecosystem with common packages pre-installed:
- Data: numpy, pandas, scipy, scikit-learn
- Web: requests, aiohttp, beautifulsoup4
- Utilities: matplotlib, PyYAML, Pillow
Check available packages:
JavaScript & TypeScript
No npm packages available - only built-in Node modules.
R
Base R only - no tidyverse packages.
Java
JShell-style execution - statement-level only.
Network Access
The sandbox has full network access for HTTP requests, API calls, and DNS resolution.
No State Persistence
Variables, files, and state do not carry over between executions. Each run_code
call is completely isolated.
Implications:
- Must re-import libraries each time
- Files written to disk are lost
- Cannot build up state across executions
Self-Hosted Setup
For self-hosted servers, configure an E2B API key. E2B provides the sandbox infrastructure.