Skip to main content
The code-interpreter template runs a Jupyter kernel inside the sandbox: variables persist between calls, packages install at runtime, and rich results like plots come back as data.

Setup

uv pip install "nullspace-sdk==0.1.9"
export NULLSPACE_API_KEY=ns_live_...
export NULLSPACE_API_URL=https://api.your-nullspace-domain

Python

interpreter_example.py
from nullspace import Sandbox

with Sandbox.create(template="code-interpreter", timeout=120) as sandbox:
    # State persists across run_code calls, like notebook cells.
    sandbox.run_code("value = 21")
    result = sandbox.run_code("value * 2")
    print("stateful result:", result.results[0].text)

    # Install a package into the live kernel.
    sandbox.install_packages(["humanize==4.9.0"])
    result = sandbox.run_code("import humanize; print(humanize.intword(1234567))")
    print("package output:", "".join(result.logs.stdout).strip())

    # Plots come back as PNG data on the result.
    plot = sandbox.run_code("""
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.show()
""")
    print("plot rendered:", any(r.png for r in plot.results))

Expected output

stateful result: 42
package output: 1.2 million
plot rendered: True
If a call fails inside the kernel, the returned result carries the error instead of raising: check result.error for the exception name, value, and traceback. Related: Code Interpreter overview · SDK guide · Charts