Skip to main content
This page is the runtime API surface of the Sandbox SDK in one place. It maps the Python and TypeScript sandbox-management APIs you’ll use to create sandboxes, execute work inside them, manage files and processes, and interact with desktop sandboxes. Each detail page linked below expands on the same APIs with longer examples and edge cases.
All method names below use the Python form. The TypeScript SDK mirrors them in camelCase (start_process → startProcess, read_file → readFile, memory_mb → memoryMb, etc.). The same JavaScript runtime API is used from Node.js.
This page focuses on the sandbox runtime SDK surface. Related interfaces documented elsewhere include the CLI and HTTP API, the image-building DSLs in Build and Import Images, and the browser/VNC integration details in Computer Use.
Every method below is also available as an async-native variant on AsyncSandbox in Python: same names and parameters, just awaited. See the Async SDK page for usage. The TypeScript SDK is already Promise-based, so the methods shown in the TypeScript tabs are the async API.

Sandbox

Sandbox is the top-level entry point for managing sandboxes in your namespace. Use Sandbox.create() to start a sandbox, Sandbox.connect() to reconnect to an existing sandbox by ID or name, or Sandbox.get_or_create() when a deterministic name should resolve to one reusable sandbox.
See Authentication for the full auth flow.

Create

Create a sandbox. Omit name for an ephemeral sandbox (cannot be suspended); pass name to create a named sandbox that supports suspend/resume. Returns a connected Sandbox handle (blocks until the sandbox is running). The auto_resume option also applies to SandboxClient.create(), create_and_connect(), and Sandbox.get_or_create() (TypeScript: autoResume, createAndConnect(), and getOrCreate()). For get-or-create, creation options apply only to a new sandbox; the default resume=True explicitly resumes an existing one regardless of its flag. Pass resume=False to attach without waking it. Python AsyncSandbox and AsyncSandboxClient accept the same option. To expose user ports for inbound traffic, call sandbox.update(exposed_ports=..., allow_unauthenticated_access=...) after create().

Create and connect

Sandbox.create() creates a sandbox and returns a live Sandbox handle you can immediately run commands against.

Create without waiting

Sandbox.create(..., wait=False) returns a PendingSandbox as soon as the sandbox is durable. ready() polls every two seconds until it runs and returns a connected Sandbox; status() fetches the current SandboxInfo once. When ready() runs out of time it raises SandboxPending and the sandbox keeps its place in the queue. See Non-blocking Sandbox Creation.

Get or create

Return the sandbox bound to a name, creating it on first use. This is the recommended factory for agent sessions that derive a sandbox name from a stable session ID. The name argument is required and must be unique within the namespace. All other creation arguments, such as image, cpus, and memory_mb, apply only when a new sandbox is created. An existing sandbox keeps its current configuration.
get_or_create() does not accept pool_id (poolId in TypeScript). A pool claim cannot assign a name during creation, so a later call could not find the claimed sandbox by name. Names cannot be assigned later through sandbox.update().

Connect

Get a Sandbox handle for an existing sandbox (by ID or name) without creating a new one. If the sandbox is still pending, connect() waits for it to run, up to request_timeout, and raises SandboxPending if it does not. Use this to rejoin a named sandbox after resume, or to operate on a sandbox a different process created.

List and get

Sandbox.connect() attaches to a single sandbox by ID or name. To enumerate all sandboxes in your namespace, use Sandbox.list().

Update

Use sandbox.update() to change automatic resume, exposed user ports, unauthenticated access, or the egress network policy. Names are immutable; set name when creating the sandbox. These examples disable automatic resume on an existing named sandbox and inspect the returned metadata:
If you already have a handle, use sandbox.update(auto_resume=False) or await sandbox.update({ autoResume: false }). Omission preserves the setting; explicit False disables it. Updating this flag neither suspends a running sandbox nor wakes a suspended one. A resources resize PATCH cannot include this or any other setting. Read the current flag with sandbox.info().auto_resume or (await sandbox.info()).autoResume. The client equivalents are client.get(sandbox_id).auto_resume and (await client.get(sandboxId)).autoResume. When proxy traffic targets a suspended sandbox with automatic resume disabled, RemoteAPIError reports status_code (statusCode in TypeScript) 409 and code SANDBOX_AUTO_RESUME_DISABLED. Explicitly resume before retrying, or enable automatic resume with an update. See Keep a sandbox suspended for a complete example.

Suspend and resume

Pause a running named sandbox in place; resume it later under the same ID with its memory, filesystem, and running processes intact. Ephemeral sandboxes return an error on suspend.
Explicit resume works even when auto_resume is False and does not change that setting. To re-enable proxy-triggered resume, call update(auto_resume=True) (update({ autoResume: true }) in TypeScript). See Keep a sandbox suspended.

Terminate

terminate() ends the sandbox permanently. Terminated is a final state and cannot be reversed.
See Lifecycle for the full state machine.

Expose and unexpose ports

Route public internet traffic to services listening on user ports inside the sandbox. Requests arrive at https://<port>-<sandbox-id-or-name>.sandbox.tensorlake.ai. Port exposure is just a sandbox.update() call: pass exposed_ports and (optionally) allow_unauthenticated_access. Pass exposed_ports=[] to remove all exposed ports.
See Networking for authenticated vs. unauthenticated access and how clients reach user ports.

Snapshot and restore

Capture a reusable artifact of the sandbox (filesystem + memory + running processes). Restore by passing snapshot_id to Sandbox.create().
Suspend pauses this sandbox; snapshot captures a reusable artifact you restore into a new sandbox. See Snapshots.

Sandbox handle

The Sandbox object returned by Sandbox.create(), Sandbox.connect(), or Sandbox.get_or_create() is how you execute work inside a running sandbox. All methods below target a single live sandbox.

Run a command

run() is the short-lived foreground execution primitive: send a command, wait for it to exit, receive captured output. Use it for the common case of “do this one thing and give me the result.”
Pass env={"KEY": "value"} (Python) or env: { KEY: "value" } (TypeScript) for per-command environment variables. See Environment Variables. See Commands & Processes for streaming, multi-step shell pipelines, and error handling.

Background processes

For long-running or concurrent work, start a process and keep the handle so you can monitor, stream output, and signal it.

Writing to stdin

Drive a process interactively from code by writing bytes to its stdin, then closing the stream when you’re done.
See Commands & Processes for the full API.

PTY sessions

Open an interactive terminal inside the sandbox. The PTY is created over HTTPS; terminal I/O then moves over a WebSocket attached to the session.
See PTY Sessions for the wire protocol, reconnect flow, and resize frames.

TCP tunnels

Forward a local TCP port to a port inside the sandbox over an authenticated WebSocket. The remote port does not need to be in exposed_ports.
See Local Tunnels for options, the relay protocol, and common port mappings.

File operations

Copy data in and out of the sandbox filesystem without spawning a shell.
See File Operations for binary uploads, recursive listings, and move/copy patterns.

Desktop sessions

Desktop sandboxes expose a higher-level remote-control handle on top of the normal Sandbox APIs. Use this with tensorlake/ubuntu-vnc to capture screenshots and drive mouse and keyboard input through the authenticated sandbox proxy.
Common desktop methods are: See Computer Use for reconnect patterns, coordinate workflows, and noVNC integration.

Terminate

Shortcut for sandbox.terminate() that uses the handle you already have.

Data models

The SDK returns typed objects for every API call. The fields below are the ones you’ll read most often. Field names shown in Python snake_case; TypeScript uses the camelCase equivalent.

SandboxInfo

Returned by sandbox.info(), client.get(), and updates; list results contain sandbox metadata. Sandbox.create() and Sandbox.connect() return handles instead.

PendingSandbox

Returned by create(wait=False).

Sandbox

Returned by Sandbox.create(), Sandbox.connect(), and Sandbox.get_or_create(). Exposes the runtime methods documented above plus:

ProcessInfo

Returned by start_process() and list_processes().

CommandResult

Returned by run().

SnapshotInfo

Returned by the snapshot APIs.

Learn more

Lifecycle

State machine, suspend/resume, timeouts.

Commands & Processes

Run commands, capture output, stream, and manage background processes.

PTY Sessions

Interactive shells over WebSocket.

File Operations

Read, write, list, delete.

Snapshots

Capture and restore full VM state.

Build and Import Images

Prebuild dependencies into reusable images.

Computer Use

Desktop sessions, screenshots, mouse, keyboard.

Networking

Expose user ports to the internet.

Environment Variables

Per-command and per-PTY environment.