# OpenAI Code Interpreter alternative: run code in your own sandbox OpenAI's Code Interpreter runs Python in a hosted container; your own sandbox runs any model's code in seven languages, on your terms. **Runtime runs the same 20-minute, 4 GiB session for $0.0104 to $0.0267, against $0.12 for OpenAI's 4 GB container.** Runtime bills the CPU the code uses and the memory it holds, so a session that mostly waits for the model costs little. OpenAI prices every container by its memory tier for each 20-minute session. OpenAI rates checked 25 September 2026; Runtime's are in [pricing](/docs/pricing). ## What Code Interpreter is Code Interpreter is a built-in tool of OpenAI's Responses API. In OpenAI's words, it "allows models to write and run Python code in a sandboxed environment", and "the model knows it as the 'python tool'". - **Containers.** The tool runs in a container. With `"type": "auto"` OpenAI makes one, or create one yourself at `/v1/containers` and pass its id. - **Memory.** `1g` (the default), `4g`, `16g` or `64g`. OpenAI's guide and pricing name memory tiers, not CPU counts. - **Lifetime.** "A container expires if it is not used for 20 minutes." Its data is then "discarded from our systems and not recoverable". - **Files.** Files in the model input are uploaded to the container for you, and files the model makes come back as annotations on its message. - **Network.** A container created through the API takes a `network_policy`: outbound access disabled, or an allowlist of domains, with optional domain-scoped secrets. ## What it costs OpenAI's price list, checked 25 September 2026: "1 GB $0.03, 4 GB $0.12, 16 GB $0.48, 64 GB $1.92 per 20-minute session per container." Its footnote adds that "eligible container sessions will be billed by the minute, with a 5-minute minimum per session." Tokens are billed on top, at the model's rates. The same sessions on Runtime at 2 vCPU and 4 GiB, which costs $0.03125 an hour while the code waits and $0.08 an hour with both CPUs busy: | Session | OpenAI, 4 GB container | Runtime, 2 vCPU and 4 GiB | | ------------------------------------ | ---------------------------------------- | -------------------------------- | | 20 minutes, mostly waiting | $0.12 | 20 / 60 × $0.03125 = $0.0104 | | 20 minutes, both CPUs busy | $0.12 | 20 / 60 × $0.08 = $0.0267 | | One minute, where per-minute applies | 5-minute minimum: 5 / 20 × $0.12 = $0.03 | 1 / 60 × $0.08 = $0.0013 at most | | 1,000 sessions of 20 minutes | $120.00 | $10.42 waiting, $26.67 busy | Model tokens are left out of both columns. Runtime has no minimum charge per session ([pricing](/docs/pricing)). ## Where your own sandbox does more | Need | OpenAI Code Interpreter | Runtime sandbox | | ------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------- | | Model | OpenAI models, through the Responses API | Any model or framework; your code calls the sandbox | | Languages in the notebook | Python, "the python tool" | Python, JavaScript, TypeScript, R, Java, Bash and Go | | The machine | OpenAI's container; a create takes memory, files, network and skills | Your image: a package recipe, any public or private image, or a Dockerfile | | An idle session | Expires after 20 minutes unused, and its data is discarded | Pauses with files, memory and processes, kept 1 to 365 days | | Copies of a session | None in OpenAI's guide | Fork 1 to 10 running copies, memory included | | Isolation | "A sandboxed environment" | A Firecracker microVM with its own Linux kernel | | Billing | Memory tier, per 20-minute session | Measured CPU plus reserved memory while running, with no minimum | The interpreter keeps variables between cells, and charts come back as PNG and data frames as tables ([code interpreter](/docs/javascript#code-interpreter)). Network rules bind root inside the sandbox too, because the host enforces them ([security](/docs/security)). ## The Runtime equivalent Install what the model needs, close the network, then run its cells. The sandbox pauses itself after ten quiet minutes and wakes on the next cell: ```ts check import { Sandbox } from "withruntime"; await using sbx = await Sandbox.create({ network: { internet: true, allow: ["pypi.org", "*.pythonhosted.org"] }, idlePauseSeconds: 600, }); await sbx.exec("pip install --quiet scikit-learn", { check: true, timeoutMs: 300_000 }); await sbx.network.set({ internet: false }); // nothing leaves while the model's code runs await sbx.interpreter.run( "from sklearn.datasets import load_iris\nX, y = load_iris(return_X_y=True)", ); const cell = await sbx.interpreter.run("X.shape"); console.log(cell.results[0]?.data["text/plain"]); // (150, 4) ``` ```python check from withruntime import Sandbox with Sandbox.create( network={"internet": True, "allow": ["pypi.org", "*.pythonhosted.org"]}, idle_pause_seconds=600, ) as sbx: sbx.exec("pip install --quiet scikit-learn", check=True, timeout_ms=300_000) sbx.network.set(internet=False) # nothing leaves while the model's code runs sbx.interpreter.run("from sklearn.datasets import load_iris\nX, y = load_iris(return_X_y=True)") cell = sbx.interpreter.run("X.shape") print(cell["results"][0]["data"]["text/plain"]) # (150, 4) ``` Expose a function like this to the model as a tool and return the cell's output as the tool result. With the OpenAI Agents SDK, `RuntimeCloudSandboxClient` runs a `SandboxAgent`'s shell and files in a Runtime sandbox with the agent unchanged ([OpenAI Agents SDK](/docs/openai-agents-sdk)). ## Which one fits - **Keep Code Interpreter** for quick Python answers inside an OpenAI conversation, when a 20-minute session and the container's own packages cover the job. - **Use your own sandbox** when the code needs packages or tools you choose, a language other than Python, a session that survives a long pause, a model from more than one provider, or a bill that follows the CPU used. Try it on the free trial: ```bash no-run npx withruntime sandbox run --trial -- python3 -c 'print(6 * 7)' ``` The first run prints a link to approve in your browser; there is no API key to copy. More: [add a code interpreter to a chatbot](/use-cases/code-interpreter-for-chatbots), [what is a code interpreter?](/glossary/code-interpreter), [data analysis agent](/use-cases/data-analysis-agent), [Claude code execution tool alternative](/compare/claude-code-execution-tool-alternative). ## Sources Checked 25 September 2026. - [OpenAI: Code Interpreter guide](https://developers.openai.com/api/docs/guides/tools-code-interpreter) - [OpenAI: API pricing](https://developers.openai.com/api/docs/pricing) - [OpenAI: containers API reference](https://developers.openai.com/api/reference/resources/containers) - Runtime [pricing](/docs/pricing), [JavaScript SDK](/docs/javascript) and [Python SDK](/docs/python) Facts on this page were checked on 25 September 2026.