- Declarative images — build images with varying dependencies on demand when creating sandboxes
- Pre-built snapshots — create and register ready-to-use snapshots that can be shared across multiple sandboxes
Declarative image building
Build images on-the-fly when creating sandboxes. Ideal for iterating quickly without creating separate snapshots. Declarative images are cached by content hash — identical manifests produce the same image. Subsequent runs reuse the cached image instantly.Sandbox.create(image=..., on_build_log=...)
When you pass an image to Sandbox.create(), the server:
- Hashes the image manifest to compute a cache key
- If cached, creates the sandbox from the existing checkpoint instantly
- If not cached, boots a build sandbox, executes each step, checkpoints the result, then creates your sandbox from it
A declarative image definition built with the
Image builder.Callback for streaming build log messages via SSE. Receives step-by-step progress updates during image building.
Creating pre-built snapshots
Create named snapshots that persist permanently and can be shared across sandboxes. Snapshots are visible in the dashboard and don’t need to be rebuilt.Snapshots(api_key=..., api_url=...)
API key. Falls back to
OPENCOMPUTER_API_KEY env var.API base URL. Falls back to
OPENCOMPUTER_API_URL env var.await snapshots.create(name, image, on_build_logs=None)
Creates a pre-built snapshot from a declarative image.
Unique name for this snapshot.
Declarative image definition.
Callback for streaming build log messages.
dict with snapshot info (id, name, status, etc.)
await snapshots.list()
Returns all named snapshots for the current organization.
list[dict]
await snapshots.get(name)
Gets a snapshot by name.
Snapshot name.
dict
await snapshots.delete(name)
Deletes a named snapshot. Existing sandboxes created from it are not affected.
Snapshot name to delete.
None
Sandbox.create(snapshot=...)
Create a sandbox from a pre-built snapshot by name.
Name of a pre-built snapshot to create the sandbox from.
Sandbox
Image configuration
TheImage class provides a fluent, immutable API for defining sandbox environments. Each method returns a new Image instance — the original is never modified.
Image.base()
Creates a new image starting from the default OpenSandbox environment (Ubuntu 22.04 with Python, Node.js, build tools, and common utilities).
image.apt_install(packages)
Install system packages via apt-get.
List of apt package names to install.
image.pip_install(packages)
Install Python packages via pip.
List of pip package names to install.
image.run_commands(*commands)
Run one or more shell commands during image build.
Shell commands to execute sequentially.
image.env(vars)
Set environment variables. Written to /etc/environment so they’re available in all sessions.
Key-value pairs of environment variables.
image.workdir(path)
Set the default working directory.
Absolute path for the working directory.
image.add_file(remote_path, content)
Embed a file with inline content into the image.
Absolute path inside the sandbox.
String content of the file.
image.add_local_file(local_path, remote_path)
Read a file from the local machine and embed it into the image.
Path to the file on the local machine.
Absolute path inside the sandbox.
image.add_local_dir(local_path, remote_path)
Recursively read a local directory and embed all files into the image.
Path to the directory on the local machine.
Absolute path inside the sandbox where the directory will be created.
image.to_dict()
Returns the image manifest as a plain dict.
Returns: dict
image.cache_key()
Computes a deterministic SHA-256 hash of the manifest for cache lookups.
Returns: str
Snapshot info fields
| Field | Type | Description |
|---|---|---|
id | str | Unique snapshot identifier |
name | str | Snapshot name |
status | str | "building", "ready", or "failed" |
contentHash | str | SHA-256 hash of the image manifest |
checkpointId | str | Linked checkpoint ID |
manifest | dict | The declarative image manifest |
createdAt | str | ISO 8601 creation timestamp |
lastUsedAt | str | ISO 8601 last usage timestamp |