# What is a code execution tool? A code execution tool is a tool an LLM calls to run the code it writes, returning the output so the model can use it in its answer. **You can host the tool yourself in a Runtime sandbox, for any model, with the internet on your terms and a bill per second of real use.** A new sandbox ran its first Python command 351 ms after the create request at the median on 24 September 2026 ([speed](/docs/speed)), fast enough to start one per call. ## Why it matters for AI agents A model predicts text; it does not compute. Asked to sum a column or parse a log, it guesses. Given a tool that runs code, it writes a short program, reads the real result and answers from that. The same tool lets an agent test a patch, convert a file or draw a chart. Tools come in two kinds, and the difference decides who runs the code: - **A server tool** runs on the model provider's side. You add it to the request and the provider runs the code in its own container. Anthropic's code execution tool is one: "The API runs every command server-side and returns the results to Claude within the same request". - **A client tool** is one you define. The model returns a call, your code runs it wherever you choose, and you send the result back. A sandbox is the usual place, because the code came from a model. ## Hosted tools in facts | Tool | Where the code runs | Documented limits | | ----------------------------- | --------------------------------------------------- | ----------------------------------------------------------- | | Anthropic code execution tool | Anthropic's container, 1 CPU, 5 GiB RAM, 5 GiB disk | Internet "completely disabled"; pre-installed packages only | | Anthropic pricing | 1,550 free hours a month per organization | Then $0.05 an hour per container, 5-minute minimum | | OpenAI Code Interpreter tool | "A fully sandboxed virtual machine" | Python; memory 1g (default), 4g, 16g or 64g | | OpenAI container lifetime | Expires after 20 minutes unused | Later calls to it fail | | Your own tool on Runtime | A Firecracker microVM per sandbox | Size, packages, network and lifetime set per sandbox | Anthropic's code execution is free when the same request also includes its web search or web fetch tool. ## Build one as a client tool Give the model a tool such as `run_code(command)` and back it with a sandbox. `withruntime/tools` hands you the tool already written, with a name, a description, a JSON Schema and a function: ```ts check import { Sandbox } from "withruntime"; import { sandboxTools } from "withruntime/tools"; await using sbx = await Sandbox.create({ network: { internet: false } }); const [exec] = sandboxTools(sbx); console.log(exec.name, exec.description); console.log(await exec.execute({ command: "python3 -c 'print(6 * 7)'" })); ``` ```python check from withruntime import Sandbox from withruntime.tools import sandbox_tools with Sandbox.create(network={"internet": False}) as sbx: run, read, write, ls = sandbox_tools(sbx) print(run("python3 -c 'print(6 * 7)'")) ``` Pass the schema to any model's tool format, run `execute` when the model calls it, and return the output. Adapters for the OpenAI Agents SDK, the Vercel AI SDK, the Claude Agent SDK, LangChain and others wrap the same tools ([frameworks](/docs/frameworks)). ## Runtime's side of the tool - **Any model,** since the sandbox is yours and the tool is ordinary code. - **Network rules** that allow a package index, deny everything, or switch the internet off, enforced on the host. - **Any package or image,** with `pip`, `npm` and `sudo apt-get` working. - **Cost:** $0.025 per vCPU-hour of measured CPU and $0.0075 per GiB-hour of memory, with no minimum ([pricing](/docs/pricing)). For notebook-style sessions that keep variables and return charts, see [code interpreter](/glossary/code-interpreter). ## Related - [Claude code execution tool alternative](/compare/claude-code-execution-tool-alternative) - [OpenAI Code Interpreter alternative](/compare/openai-code-interpreter-alternative) - [What is a code interpreter?](/glossary/code-interpreter) - [How to run untrusted code from an LLM safely](/use-cases/run-untrusted-llm-code) ## Sources Checked 25 September 2026. - [Anthropic: code execution tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool): how it runs, container limits and pricing - [OpenAI: Code Interpreter](https://developers.openai.com/api/docs/guides/tools-code-interpreter): container, memory options and expiry Facts on this page were checked on 25 September 2026.