Skip to main content

Overview

The Python SDK exposes two namespaces for managing the code-interpreter sandbox that backs each agent’s bash and code_interpreter tools:
  • client.code_interpreter.templates — create, get, update, and delete custom Docker-based sandbox templates.
  • client.agents.add_code_interpreter / get_code_interpreter / remove_code_interpreter — attach, inspect, and detach a template on an agent (= prompt version).
Environments are managed implicitly. When you attach a template to an agent, the sandbox env is auto-provisioned by the backend; the returned AgentToolBinding.env_id is informational only.

Quick Start

Templates

Create Template

Submit a custom-template build; returns immediately with status="pending".
Returns a Template handle with .refresh() and .wait_until_ready() bound. Status is "pending" until the first workflow activity inserts the row.

Get Template

Fetch a single template row by id.
Raises NotFoundError if the template doesn’t exist or is in another project.

Update Template

Replace the template’s commands and rebuild the same sandbox image.
The same sandbox image is rebuilt; the previous image is overwritten. Already-running sandboxes keep their old snapshot until they’re killed or idled out — the next sandbox spawn picks up the new image.

Delete Template

Hard-delete the template row and its sandbox image.
Idempotent — a 404 is silently absorbed. Raises if the template is still bound to an environment.

Wait Until Ready

Block until the template build completes; raise on failure.
Returns self once status reaches "ready". Raises BuildFailedError when the server reports status="failed" — the captured stderr tail is on error_message.

Refresh

Re-fetch the row from the server; mutate self in place.
Returns self, so callers can chain. Tolerates 404 for a short grace window after create / update — the row may not exist yet because the first workflow activity hasn’t run.

Agent Bindings

Attach Code Interpreter

Attach (or update) the code-interpreter tool on an agent version.
Attaching is upsert: calling the method again with different config replaces the previous binding. The agent (= prompt) must already exist. Returns an AgentToolBinding; binding.env_id is the auto-provisioned sandbox env id (informational only).

Get Binding

Fetch the agent’s current code-interpreter binding.
Returns an AgentToolBinding, or None if no binding exists for that agent version.

Remove Code Interpreter

Detach the code-interpreter tool from an agent version.
Idempotent — a 404 is silently absorbed.

Dockerfile Commands

commands is a list[str] of raw Dockerfile instructions appended verbatim to the platform’s base Dockerfile. The base ships the systemd
  • Jupyter setup that backs the MCP tools.

Allowed Instructions

RUN, ENV, WORKDIR, USER, ARG, LABEL — plus the rest of the Docker instruction set that doesn’t break the base. Server-side validation is deny-list, not allow-list, so harmless no-ops like EXPOSE and SHELL are silently accepted.

Rejected Instructions

The validator hard-rejects five instructions with explicit per-instruction error messages:

Typo Catcher

Each line must start with a recognised Docker instruction keyword. A line like "pip install pydantic-ai" returns a 422 with a did you forget RUN? hint immediately, instead of failing 30 seconds into the sandbox build.

Structural Limits

  • ≤ 64 commands per template.
  • ≤ 4 KB per command line.
  • No NUL bytes, no bare CRs.

Response Objects

Template

Handles returned by create(), get(), and update() carry .refresh() and .wait_until_ready() bound to the originating client.

AgentToolBinding

NetworkPolicy

  • "disabled" — block all egress (default).
  • "open" — unrestricted egress.
  • "filtered" — caller-defined allow / deny lists.
allow_out / deny_out accept IP literals, CIDR ranges, domain names, wildcard domains ("*.example.com"), and the case-insensitive sentinel "ALL_TRAFFIC" (which expands to 0.0.0.0/0). Allow takes precedence over deny.

BuildFailedError

Raised by Template.wait_until_ready() when the build workflow reports status="failed".

Async Client

The same surface exists on AsyncBudClient:

Error Handling

Limits

  • No file uploads — COPY / ADD are rejected. Heredoc in RUN or RUN curl are the documented workarounds.
  • No template versioning — edits are destructive. To preserve an old recipe, create a new template before editing the old one.
  • No template list endpoint in the SDK. Keep the id from create().
  • No environment CRUD in the SDK. agents.add_code_interpreter does it for you; project deletion cascades the cleanup.
  • Embedded credentials in RUN pip install --index-url=… are baked into the image. Treat any image you build as you would any artifact: if it contains secrets, do not share it.

Next Steps

Inference

Invoke agents that use your code-interpreter binding

Code Examples

Complete code examples and patterns