[ code interpreter api · run code ]
A code interpreter API for your AI app
Run model-generated Python and shell, stream the output back, capture results and files, and keep interpreter state alive between calls. Built for agent loops and notebook-style execution.
[ two ways to run ]
Snippets or processes, your call
Code Runs
Execute a Python or shell snippet against a live Code Context and get results or a stream back. No durable resource to clean up.
code.run({ language: "python" })Code Contexts
A language-specific interpreter state inside a sandbox, identified as cctx_…. Variables survive across runs in the same context.
cctx_7f3a…Commands
When you need an audited process with an exit code and recorded logs, run a Command instead of a Code Run.
commands.run("python3 main.py")[ streaming ]
Run code and read the result
Send code, get back stdout, the return value, and any execution error. Stream it when the model needs to watch long output, or take the result synchronously when you just need the answer.
import { createCrowNestClient } from "@crownest/sdk";
const client = createCrowNestClient();
const sandbox = await client.sandboxes.create({ template: "python" });
// run model output and stream stdout + results back
const result = await sandbox.code.run({
language: "python",
code: "import pandas as pd; print(pd.__version__)",
onStdout: (chunk) => process.stdout.write(chunk),
});
console.log(result.error ?? "ok");
await sandbox.kill();[ around the code ]
More than an eval endpoint
Files in /workspace
Read and write files the code produces, then promote the ones worth keeping into durable artifacts.
Authenticated previews
If the code starts a server, expose the port as a URL that still requires authentication.
Per-second billing
Pay for the seconds the sandbox is alive, metered in compute_unit_seconds, not for idle capacity.
Isolated by default
Each sandbox is its own Linux box, so one tenant's code never sees another's.
[ questions ]
Code interpreter API FAQ
- What is a code interpreter API?
- It is an API your application calls to run code that a model wrote, then read the result. CrowNest runs the code inside an isolated sandbox and returns stdout, return values, files, and execution errors, synchronously or streamed.
- How is a Code Run different from a Command?
- A Code Run executes a snippet against a live interpreter Code Context and returns or streams the result without creating a durable record. A Command is a tracked top-level process with an exit code and recorded logs. Use Code Runs for notebook-style snippets and Commands for processes you want to audit.
- Does interpreter state persist between calls?
- Within a sandbox, a Code Context keeps language state alive, so variables defined in one Code Run are available in the next. Code Runs themselves are not persisted as resources; an idempotent replay returns the completed result for 24 hours.
- Can I stream output as the code runs?
- Yes. Streaming returns stdout, stderr, and results over SSE as they happen, which is what you want when an agent reacts to long-running output.
Execute model output without the risk
Free $10 credit, no card. Run your first snippet through the interpreter API in a few minutes.