Skip to main content
Use the code-interpreter template when you want notebook-style execution inside a hosted sandbox. It adds stateful cells, package installation, stdout/stderr callbacks, structured results, artifacts, and language contexts on templates that include them. Use raw Commands instead when you only need a process to run and return stdout or stderr.

Quick Example

from nullspace import Sandbox

with Sandbox.create(template="code-interpreter", timeout=120) as sandbox:
    execution = sandbox.run_code("x = 40 + 2\nx")
    print(execution.results[0].text)

When To Use It

NeedUse Code Interpreter?
Keep variables between cellsYes. Use contexts to preserve kernel state.
Return rich results or downloadable artifactsYes. Results can include text, images, HTML, and files.
Stream stdout and stderr during executionYes. Use callbacks or streaming APIs.
Run a normal CLI command or serviceUsually no. Use Commands instead.
Preinstall a repeatable analysis stackBuild a custom template and use it with Code Interpreter.

Core Concepts

ConceptMeaning
Templatecode-interpreter includes the runtime for notebook-style execution.
ContextA stateful kernel namespace that can keep variables and imports warm.
RunOne code execution request, with logs, results, artifacts, and errors.
ArtifactA generated file or rich output your app can inspect or download.

Package Installs

sandbox.install_packages(["humanize==4.9.0"])
result = sandbox.run_code(
    "import humanize\nprint(humanize.intword(1234567))"
)
print("".join(result.logs.stdout))
Package installs affect the running sandbox. Use Templates when the same libraries should be available on every create.

Rich Output

plot = sandbox.run_code("""
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.show()
""")

has_png = any(
    result.png or (result.data and "image/png" in result.data)
    for result in plot.results
)
print(has_png)

Guides

Analyze data with AI

Run stateful Python, R, JavaScript, TypeScript, Java, or Bash cells.

Charts and visualizations

Generate static charts, interactive HTML outputs, and downloadable files.

Supported languages

Choose a kernel and keep state in language-specific contexts.

Streaming

Stream stdout, stderr, results, artifacts, and errors as code executes.