# Claude code execution tool alternative: run Claude's code in your own sandbox Anthropic's code execution tool runs Claude's code in a 1-CPU, 5 GiB container with no internet; your own sandbox adds packages and network. **Runtime bills a one-minute run as one minute: 1,000 of them cost $1.04 on Runtime against $4.17 under the tool's 5-minute minimum**, once its free hours are used. A Runtime sandbox also reaches the internet you allow, installs any package, and runs code from any model. Anthropic's terms checked 25 September 2026; Runtime's are in [pricing](/docs/pricing). ## What the code execution tool is A server tool in Anthropic's Messages API. It "allows Claude to run Bash commands and manipulate files, including writing code, in a secure, sandboxed environment." It is generally available and needs no beta header. | Version | What it adds | | ------------------------- | ------------------------------------------------------------------------------ | | `code_execution_20250825` | Bash commands and file operations | | `code_execution_20260120` | Python state kept between requests, and programmatic tool calling | | `code_execution_20260521` | The same runtime; tells Claude about the 90-second limit per programmatic cell | The container, as Anthropic documents it: | Property | Anthropic's figure | | ------------- | ----------------------------------------------------------------------------------------- | | CPU | 1 CPU | | Memory | 5 GiB RAM | | Disk | 5 GiB workspace storage | | Python | 3.11, on x86_64 Linux | | Internet | "Completely disabled for security" | | Packages | Only the pre-installed ones, such as pandas, scikit-learn and matplotlib | | Lifetime | Expires 30 days after creation; checkpointed after about 5 idle minutes | | Reuse | A new container per request unless you pass back an earlier container's id | | Where it runs | Claude API, Claude Platform on AWS, Microsoft Foundry; not Amazon Bedrock or Google Cloud | Anthropic lists the tool as not eligible for zero data retention. ## What it costs Anthropic's pricing, checked 25 September 2026: - Free when the request also includes web search or web fetch (`web_search_20260209`, `web_fetch_20260209` or later). - Otherwise billed by execution time, with a 5-minute minimum. - Each organization gets 1,550 free hours a month, then $0.05 per hour per container. - Execution time is billed when files are in the request, even if the tool is not called. The same work on Runtime at 1 vCPU and 5 GiB, which costs $0.03875 an hour waiting (memory plus the 50-millicore CPU floor) and $0.0625 with the CPU busy: | Job, past the free hours | Claude code execution | Runtime, 1 vCPU and 5 GiB, CPU busy | | ----------------------------- | ------------------------ | ----------------------------------- | | One run of 60 seconds | 5 / 60 × $0.05 = $0.0042 | 1 / 60 × $0.0625 = $0.0010 | | 1,000 runs of 60 seconds | $4.17 | $1.04 | | One hour, mostly waiting | $0.05 | $0.03875 | | One hour, CPU busy throughout | $0.05 | $0.0625 | Tokens are left out of both columns. The tool's 1,550 free hours each month are worth $77.50 at its rate. For long, CPU-bound hours inside that allowance the tool is the cheaper choice; for short runs, and for code that needs the network, Runtime is. ## Where your own sandbox does more - **Internet on your terms.** Allow only the hosts a task needs, deny others, or switch it off, at create or at any time; the rules bind root inside the sandbox ([the network](/docs/sandbox-environment#the-network)). - **Any package, any image.** `pip install`, `npm install` and `sudo apt-get` work, and a custom image built from a recipe, an image or a Dockerfile starts every sandbox ready ([custom images](/docs/images)). - **More than one CPU.** A default sandbox has 2 vCPUs and 4 GiB, and `vcpu`, memory and disk are set per sandbox, rather than one fixed size. - **Whole-machine pause.** A paused sandbox keeps files, memory and running processes for 1 to 365 days, and forks copy a running one. - **Any model.** The same sandbox serves Claude, another provider's model, or your own code, and the Claude Agent SDK connects to it with `runtimeMcpServer(sbx)` ([Claude Agent SDK](/docs/frameworks#claude-agent-sdk)). - **Keys it cannot read.** A secret reaches the sandbox as a placeholder the host's proxy swaps for the value on its own hosts ([secrets](/docs/security#secrets-sandboxes-never-see)). ## The Runtime equivalent Define your own tool, say `run_python(code)`, and run what Claude sends in a fresh sandbox that may reach PyPI and nothing else: ```ts check import { Sandbox } from "withruntime"; export async function runPython(code: string) { await using sbx = await Sandbox.create({ network: { internet: true, allow: ["pypi.org", "*.pythonhosted.org"] }, timeoutSeconds: 600, onLeaseEnd: "stop", }); await sbx.files.write("/workspace/main.py", code); const run = await sbx.exec(["python3", "main.py"], { timeoutMs: 120_000 }); return { exitCode: run.exitCode, stdout: run.stdout, stderr: run.stderr }; } ``` ```python check from withruntime import Sandbox def run_python(code: str) -> dict: with Sandbox.create( network={"internet": True, "allow": ["pypi.org", "*.pythonhosted.org"]}, timeout_seconds=600, on_lease_end="stop", ) as sbx: sbx.files.write("/workspace/main.py", code) run = sbx.exec(["python3", "main.py"], timeout_ms=120_000) return {"exit_code": run.exit_code, "stdout": run.stdout, "stderr": run.stderr} ``` Return the dictionary as the tool result. The sandbox stops when the block ends, even after an error. With no size given it has 2 vCPUs and 4 GiB. ## Which one fits - **Keep the code execution tool** for analysis Claude does inside a conversation with the pre-installed libraries, especially alongside web search or web fetch, where it is free. - **Use your own sandbox** when the code needs a package, an API or a repository from the internet, more than one CPU, a session that keeps its processes, or a model other than Claude. Try it on the free trial, 50 sandbox hours with no card: ```bash no-run npx withruntime sandbox run --trial -- python3 -c 'print(6 * 7)' ``` More: [Runtime for Claude Code](/integrations/claude-code), [OpenAI Code Interpreter alternative](/compare/openai-code-interpreter-alternative), [run untrusted LLM code](/use-cases/run-untrusted-llm-code), [egress control](/glossary/egress-control). ## Sources Checked 25 September 2026. - [Anthropic: code execution tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool), including its containers, reuse and pricing sections - Runtime [pricing](/docs/pricing), [the sandbox environment](/docs/sandbox-environment) and [frameworks](/docs/frameworks) Facts on this page were checked on 25 September 2026.