ModelRefs / Code Interpreter — AI Glossary
Code Interpreter — AI Glossary
A sandboxed execution environment that lets an LLM write and run code, capturing stdout/stderr and returning results. Sandboxing is critical for security.
Overview
Code interpreters enable data analysis, math verification, file manipulation, and chart generation by running LLM-generated Python (or other languages). OpenAI's Advanced Data Analysis, Anthropic's tool use, and E2B are common implementations. Sandboxing is critical for security.
Reference details
| Topic | agents |
|---|---|
| Last reviewed | 2026-06-24 |
Related terms
How it works
- A sandbox is provisioned per session — a container or microVM with its own filesystem, a CPU and memory cap, a wall-clock timeout, and a network policy that is usually deny-by-default.
- The model's generated code is written into that sandbox as a file or sent to a kernel process running inside it, rather than being evaluated in the harness itself.
- Execution is bounded by those limits, so a non-terminating loop or a runaway allocation ends as a timeout or a kill rather than as an outage.
- Standard output, standard error and the exit status are captured and returned to the model as a tool result, which is how a traceback becomes something it can respond to.
- Files the code wrote — charts, converted data, generated documents — are collected from the sandbox filesystem as artifacts separately from the textual output.
- The kernel persists for the session, so variables and imports survive between calls, which is what lets the model build up an analysis in steps instead of resending state each time.
Example: Why it beats the model doing the sum
Asked to compute a median over 4,000 rows, a model estimates and is confidently wrong. Given execution, it writes three lines of pandas, runs them, and reports the actual value. The model's job changes from computing the answer to writing code that computes it — which it is far better at.
Commonly confused with
The sandbox is the feature, not an implementation detail. Code interpretation means running model-generated code, so isolation, resource limits and network policy are the product. An unsandboxed interpreter is remote code execution with extra steps.
When to use it
Reach for it when:
- Data analysis, transformation or verifiable computation
- Charts and file manipulation where the artifact is the output
- Checking a model's arithmetic rather than trusting it
Reach for something else when:
- The sandbox has network access it does not need
- Untrusted user input reaches the generated code unfiltered
- A fixed query or script would do the job deterministically
Referenced by
This term is used by the following ModelRefs references:
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Code Interpreter — AI Glossary.
Frequently asked questions
What is Code Interpreter?
A sandboxed execution environment that lets an LLM write and run code, capturing stdout/stderr and returning results.
What concepts are related to Code Interpreter?
Closely related concepts include tool use, agent, function calling.