# What is a code interpreter? A code interpreter lets an AI model run code in a live session that keeps variables between runs and returns charts and tables. **On Runtime every sandbox has one, in seven languages, inside its own Firecracker microVM.** Python, JavaScript, TypeScript, R, Java, Bash and Go run as notebook-style sessions, and a new sandbox ran its first Python command 351 ms after the request at the median, measured on 24 September 2026 ([speed](/docs/speed)). ## Why AI agents use one A model is poor at arithmetic and data work in its head, and good at writing code that does it. A code interpreter closes the loop: the model writes a cell, the interpreter runs it, and the model reads the output and writes the next cell. Because state persists, the model can load a file once and then ask ten questions of it, the way a person works in a notebook. Running that code needs isolation. The model may have been given a hostile file, or a prompt injection may tell it to read your secrets. An interpreter inside a sandbox keeps the damage to a throwaway machine. ## Runtime's code interpreter | Fact | Value | | ----------------- | ------------------------------------------------------------------------------- | | Languages | Python, JavaScript, TypeScript, R, Java, Bash, Go | | In the image | Python, JavaScript, TypeScript and Bash; R, Java and Go install on first use | | State | Variables persist between runs; Go keeps functions, types and imports | | Rich results | matplotlib charts and R plots as PNG; pandas and R data frames as tables | | Files | `display` returns a .png, .svg, .html or .csv file as a result, in any language | | Python data tools | NumPy, pandas and matplotlib in the default image | | Isolation | A Firecracker microVM with its own kernel; network rules enforced on the host | On 23 September 2026 the first use of Java or Go took about 35 seconds and R about 90, once per sandbox. Bake them into a [custom image](/docs/images) with `apt` to skip it ([code interpreter](/docs/javascript#code-interpreter)). ## Run a cell ```ts check import { Sandbox } from "withruntime"; await using sbx = await Sandbox.create({ network: { internet: false } }); await sbx.interpreter.run("import math\nx = math.pi"); const cell = await sbx.interpreter.run("round(x * 2, 3)"); console.log(cell.results[0]?.data["text/plain"]); // 6.283 ``` ```python check from withruntime import Runtime runtime = Runtime() with runtime.sandboxes.create() as sbx: sbx.interpreter.run("import math\nx = math.pi") cell = sbx.interpreter.run("round(x * 2, 3)") print(cell["results"][0]["data"]["text/plain"]) ``` The second cell reads `x` from the first. Pass `{ language: "typescript" }` (or `language="r"` in Python) to run another language. An agent connected through MCP gets the same sessions as the `runtime_sandbox_interpreter_run` tool ([MCP](/docs/mcp#tools)). ## What it costs The interpreter costs nothing beyond its sandbox. Runtime charges $0.025 per vCPU-hour of measured CPU and $0.0075 per GiB-hour of memory, so a 2 vCPU, 4 GiB sandbox costs $0.03125 an hour while the model thinks and $0.08 an hour with both CPUs busy ([pricing](/docs/pricing)). New accounts get 50 free sandbox hours, no card. ## Related - [A code interpreter for chatbots](/use-cases/code-interpreter-for-chatbots) - [A data analysis agent](/use-cases/data-analysis-agent) - [How to run untrusted code from an LLM safely](/use-cases/run-untrusted-llm-code) - [What is an agent sandbox?](/glossary/agent-sandbox) Facts on this page were checked on 25 September 2026.