Code interpreter
Replace OpenAI's code-interpreter with a self-hosted, stateful Python REPL in your own sandbox.
The code-interpreter template ships a Jupyter-compatible Python kernel inside a
Firecracker microVM. Combined with REPL sessions, you get the same UX as the OpenAI
"Advanced Data Analysis" tool — but running on your own infra.
One-shot exec
sb = Sandbox(template="code-interpreter")
result = sb.run("python -c 'print(2+2)'")
print(result.stdout) # "4\n"This spawns Python fresh each call. Variables don't persist between runs.
REPL session (stateful)
repl = sb.repl(language="python")
repl.execute("x = 42")
repl.execute("y = x * 2")
out = repl.execute("print(x, y)")
print(out.stdout) # "42 84\n"Behind the scenes the agent maintains a persistent Jupyter kernel inside the sandbox. State (variables, imports, package installs) persists between calls.
Rich outputs
Jupyter-style rich outputs (matplotlib plots, pandas DataFrames, IPython HTML) are serialized back to the SDK:
out = repl.execute("""
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.title('demo')
plt.show()
""")
for item in out.display:
if item.mime == "image/png":
with open("plot.png", "wb") as f:
f.write(item.data)File uploads
sb.write("/workspace/data.csv", open("./data.csv", "rb").read())
repl.execute("""
import pandas as pd
df = pd.read_csv('/workspace/data.csv')
print(df.describe())
""")Persistent across sessions
vol = Volume.get_or_create(name=f"user-{user_id}", size_gb=10)
sb = Sandbox(
template="code-interpreter",
volumes=[vol.mount("/workspace")],
)When the user comes back tomorrow, mount the same volume and cd /workspace —
all their notebooks, data, and package installs are still there.