---
title: "Sandboxes for code interpreters in AI apps: isolated, ready in milliseconds"
description: "Promigence runs the code your AI app writes in an isolated sandbox that is ready in milliseconds, behind the sandbox API many AI apps already use."
url: "https://www.promigence.ai/for/code-interpreters"
site: "Promigence"
---

# Code interpreters that answer while your user is still looking

Promigence runs the code your AI app writes in an isolated sandbox that is ready in milliseconds. In our benchmark a code-interpreter session took 1.15 seconds from start to result at the median, and Promigence works with the sandbox API many AI apps already use.

**Who this is for:** Teams building AI analysts, chat-with-your-data features and any AI app that runs code for its users.

## What breaks today
### Your user is watching
A code-interpreter answer is interactive. Every second of sandbox start-up is a second your user stares at a spinner in your product.

### Model-written code needs a real boundary
The model writes the code, and anyone can prompt the model. It has to run somewhere isolated, with network access you control.

### Switching providers should not be a rewrite
Code written against one sandbox API should not have to change to move to a faster one.

## What changes with Promigence
### Ready in milliseconds
A sandbox is ready for its first command 8 milliseconds after it is requested.

### Isolated, with network you decide
Each session runs in its own isolated sandbox, which can sit behind an outbound allow-list.

### A drop-in for the API you use
Promigence works as a drop-in replacement for the sandbox API many AI apps already use, so moving over is a small code change.

## A clean sandbox, then the code your model wrote
```bash
# A fresh sandbox from the base image
promigence fork --count 1 --cap 1

# Run the model's code, isolated
promigence exec --sandbox "$SANDBOX" -- python3 analysis.py
```

## Which code interpreter API should an AI app use to execute Python?

Choose one that gives each user session an isolated sandbox of its own, answers before the user tires of the spinner, and lets you switch the network off and cap what a session spends. On Promigence a sandbox is ready for its first command 8 ms after the request, a notebook-style cell runs in 8.9 ms at the median, and code written for the sandbox API many AI apps already use moves over with a small change. Billing is per second, with a quote and a hard spend cap before anything runs.

## How it works

### Build the environment once

Make a snapshot that holds the libraries your model reaches for, such as pandas, with a verify command that has to exit 0 or nothing is stored. Name it `my-analysis-env` to match the code below; the MCP execute-tool guide shows the build command for a pandas environment. Sessions then start from that one clean environment, so a package installed by one user's code is never there for the next user. The build is billed per second while it runs, at most $0.17 at the small size.

### Run each answer's code in a sandbox of its own

Write the model's program into the sandbox as a file, run it, then read the exit code and output. The SDK's compatibility `Sandbox` class keeps the calls you know from other sandbox APIs, and `spendCap` puts a dollar ceiling on the session. A non-zero exit is a normal answer: show it to the user, or hand the error back to the model for another try (`throwOnExit: false` on `commands.run` returns it as a result instead of an error).

```typescript
import { Sandbox } from "@promigence/sdk";

const modelWrittenCode = "print(sum(range(10)))"; // the Python your model wrote

const sandbox = await Sandbox.create("my-analysis-env", { spendCap: 1 });

await sandbox.files.write("/tmp/job.py", modelWrittenCode);
const res = await sandbox.commands.run("python3 /tmp/job.py");
console.log(res.exitCode, res.stdout);

await sandbox.kill();
```

### Open the network only where the code needs it

Most analysis code needs no network at all, and a sandbox can start with none. When a session must install a package, name the package index hosts and nothing else. Afterwards, `promigence sandbox network SID` lists what the sandbox may reach and every host it was refused, which tells you what the code tried to do.

```bash
promigence fork --snapshot my-analysis-env --count 1 --cap 1 \
  --allow pypi.org --allow files.pythonhosted.org
```

### End the session, or let it sleep

Kill the sandbox when the conversation is over: its bill stops and its files are gone. For a user who will be back in a few minutes, pause it instead. A paused sandbox bills no seconds and keeps its files for 30 days, and with `autopause` it pauses itself when the user goes quiet and wakes on the next request.

```bash
promigence sandbox kill SID
```

## What you get, in numbers

| What | Result | Conditions |
|---|---|---|
| Ready for its first command | 8 ms | create to first command, 2 vCPU / 4 GiB, n = 100, p50 [Source](https://www.promigence.ai/#numbers) |
| One notebook-style code cell | 8.9 ms | p50 (p95 9.3 ms), through the public API from a client in the same region, 100 runs, measured 21 and 22 September 2026 [Source](https://www.promigence.ai/#numbers) |
| 100 sandboxes started at once, slowest 5% | 0.94 s | p95, every run completed, n = 400 [Source](https://www.promigence.ai/#numbers) |
| Wake a paused sandbox | 104 ms | resume to first database query, n = 100, p50; 127 ms under load [Source](https://www.promigence.ai/#numbers) |
| Small sandbox, per second | $0.000046 | 2 vCPU / 4 GiB, $0.17 an hour at list [Source](https://www.promigence.ai/#pricing) |

## What it costs

An AI analyst feature answers 1,000 questions a day. Each question runs in a small sandbox (2 vCPU, 4 GiB) for 4 minutes of running time, and the sandbox is ended or paused afterwards.

1,000 sessions × 240 s × $0.000046 a second = $11.04

Total: $11.04 a day, about $331 over a 30-day month.

Give each sandbox a 30-minute timeout and a $1 cap: its quote, 1,800 s × $0.000046 = $0.08, sits under the cap, so it starts, and no single sandbox can cost more than $1. Paused time is not billed. Building the environment is billed once, at most $0.17 at small.

## Security and limits

- One user's sandbox cannot see, reach or address another user's, or anyone else's.
- A session can run with no network at all, or behind an outbound allow-list of the hosts it needs.
- Secrets are stored once, injected at run time and never passed on a command line; a snapshot you build never holds one unless you force it.
- Whatever a session's code changes is discarded when its sandbox ends, unless you keep it.

## Related

- [Run LLM-generated code safely](https://www.promigence.ai/docs/guides/run-ai-written-code-safely)
- [Build an MCP server with an execute tool backed by a sandbox](https://www.promigence.ai/docs/guides/mcp-execute-tool)
- [Give every user of your product their own sandbox](https://www.promigence.ai/docs/guides/sandbox-per-user)
- [Run Vercel AI SDK agents in a Promigence sandbox](https://www.promigence.ai/docs/guides/vercel-ai-sdk)
- [Quickstart](https://www.promigence.ai/docs/quickstart)
- [What is Promigence? Sandboxes for AI agents, explained](https://www.promigence.ai/blog/what-is-promigence)

## Questions

### How fast does a code-interpreter sandbox start on Promigence?

A sandbox is ready for its first command 8 ms after it is requested, at the median (2 vCPU / 4 GiB, n = 100). After that, a notebook-style cell runs in 8.9 ms at p50. Start a hundred sessions at once and the slowest 5% take 0.94 s.

### Do a user's files survive between messages?

Yes. Reuse one sandbox for the whole conversation and the files it wrote are still there on the next call, or pause it between messages and it keeps them for 30 days without billing seconds. When the user leaves for good, kill it and the files go with it.

### What stops prompt-injected code from reaching my systems?

The sandbox has only the network you give it. Start sessions with no network, or with an allow-list naming the few hosts the code needs, and read the refused hosts afterwards. Keys your app holds stay out of the sandbox: store them as secrets, and bind a key to its host so the code never sees the value.

### Do I have to rewrite code built on another sandbox API?

Not much. The TypeScript SDK's compatibility `Sandbox` class carries the familiar calls (`Sandbox.create`, `files.write`, `commands.run`, `kill`), so existing call sites keep working through it. Try your own against it before you move traffic over.

### How much does one code-interpreter session cost?

A small sandbox costs $0.000046 a second, about $0.17 an hour, billed only while it runs. Four minutes of running time comes to about $0.01. Set a cap per sandbox, and a start whose quote is over it is refused before anything runs.

### Can the interpreter run languages other than Python?

Yes. The execute tool in the MCP guide accepts Python and JavaScript as well as bash scripts, and any other language works once its runtime is in the snapshot you build.

### Should I write my own MCP execute tool or use the one in the CLI?

Write your own when the tool is part of a product you serve to other people and its rules belong in your code; the MCP guide has a complete server in TypeScript and Python. For a coding assistant on your own machine, `promigence mcp` is ready-made, and `claude mcp add promigence -- promigence mcp` adds it to Claude Code.

### What happens when the model's code loops forever?

Three limits stop a runaway loop. A command timeout ends that one script, the sandbox's timeout ends the session, and the spend cap pauses the sandbox, files intact, the moment it is reached.

