Installation
Sandbox
Static Methods
Sandbox.create(opts?): Promise<Sandbox>
Create a new sandbox.
Sandbox.connect(sandboxId, opts?): Promise<Sandbox>
Connect to an existing sandbox.
Sandbox.createFromCheckpoint(checkpointId, opts?): Promise<Sandbox>
Create a new sandbox from a checkpoint.
Sandbox.createCheckpointPatch(checkpointId, opts): Promise<PatchResult>
Create a patch for a checkpoint.
Sandbox.listCheckpointPatches(checkpointId, opts?): Promise<PatchInfo[]>
Sandbox.deleteCheckpointPatch(checkpointId, patchId, opts?): Promise<void>
Instance Methods
sandbox.kill(): Promise<void>
Terminate the sandbox.
sandbox.isRunning(): Promise<boolean>
Check if the sandbox is running.
sandbox.hibernate(): Promise<void>
Snapshot VM state and stop. No compute cost while hibernated.
sandbox.wake(opts?): Promise<void>
Resume a hibernated sandbox.
sandbox.setTimeout(timeout): Promise<void>
Update the idle timeout.
sandbox.createCheckpoint(name, opts?): Promise<CheckpointInfo>
Create a named checkpoint. Full checkpoints are limited to 10 per sandbox; disk-only checkpoints are limited to 100 per sandbox. Pass retentionPolicy: { mode: "delete_oldest", maxCount: 10 } for full checkpoints or retentionPolicy: { mode: "delete_oldest", maxCount: 100 } with kind: "disk_only" to delete the oldest eligible checkpoint of the same type before creating a new one.
sandbox.listCheckpoints(): Promise<CheckpointInfo[]>
List all checkpoints for the sandbox.
sandbox.restoreCheckpoint(checkpointId): Promise<void>
Revert in-place to a checkpoint.
sandbox.deleteCheckpoint(checkpointId): Promise<void>
Delete a checkpoint.
sandbox.createPreviewURL(opts): Promise<PreviewURLResult>
sandbox.listPreviewURLs(): Promise<PreviewURLResult[]>
sandbox.deletePreviewURL(port): Promise<void>
Properties
Types
SandboxOpts
CheckpointInfo
PatchInfo
PatchResult
PreviewURLResult
Usage & Tags
Query billing-aligned usage, inspect per-sandbox memory points, and manage sandbox tags used for grouping. Full reference: Usage & Tags.Preview: Usage and tag APIs are new. Endpoints, response fields,
and SDK method names may change before GA; temporary inaccuracies or
rough edges are possible while the surface settles.
usage.forSandbox(sandboxId, opts?): Promise<SandboxUsageResponse>
Return 1-minute allocated and used memory points for one sandbox.
from and to accept ISO dates (YYYY-MM-DD) or RFC3339
timestamps; default window is the last hour.
usage.bySandbox(opts?): Promise<UsageBySandboxResponse>
Rank sandboxes by usage. Supports ISO date or RFC3339 from / to,
filter, sort, limit, and cursor.
usage.byTag(tagKey, opts?): Promise<UsageByTagResponse>
Group usage by one tag key, with an untagged sibling bucket.
tags.set(sandboxId, tags): Promise<{ tags; tagsLastUpdatedAt }>
Replace the full tag set for a sandbox. {} clears all tags.
tags.get(sandboxId): Promise<{ tags; tagsLastUpdatedAt }>
Read the current tag set for a sandbox.
tags.listKeys(): Promise<TagKeyInfo[]>
List tag keys seen in the organization.
*GbSeconds fields are GiB-seconds. For example, 4096 MiB
provisioned for one minute reports 240 memoryAllocatedGbSeconds.
Agent
Accessed viasandbox.agent.
sandbox.agent.start(opts?): Promise<AgentSession>
Start an agent session.
sandbox.agent.attach(sessionId, opts?): Promise<AgentSession>
Reconnect to a running agent session. Accepts onEvent, onError, onExit, onScrollbackEnd.
sandbox.agent.list(): Promise<AgentSessionInfo[]>
List all agent sessions.
AgentSession
Types
AgentEvent
McpServerConfig
Exec
Accessed viasandbox.exec.
sandbox.exec.run(command, opts?): Promise<ProcessResult>
Run a command synchronously.
sandbox.exec.start(command, opts?): Promise<ExecSession>
Start a long-running command with streaming.
sandbox.exec.background(command, opts?): Promise<ExecSession>
Alias for start. Same signature and return type — use when the intent is “run this in the background and observe it”.
sandbox.exec.shell(opts?): Promise<Shell>
Open a stateful shell session whose cwd, env vars, and shell functions persist across .run() calls. Foreground-only. See the full reference.
sandbox.exec.attach(sessionId, opts?): Promise<ExecSession>
Reconnect to a running exec session.
sandbox.exec.list(): Promise<ExecSessionInfo[]>
List all exec sessions.
sandbox.exec.kill(sessionId, signal?): Promise<void>
Kill an exec session. Default signal: 9 (SIGKILL).
ExecSession
Types
ProcessResult
ExecSessionInfo
Filesystem
Accessed viasandbox.files.
sandbox.files.read(path): Promise<string>
Read a file as a UTF-8 string.
sandbox.files.readBytes(path): Promise<Uint8Array>
Read a file as raw bytes.
sandbox.files.write(path, content): Promise<void>
Write content to a file. Accepts string or Uint8Array.
sandbox.files.list(path?): Promise<EntryInfo[]>
List directory contents. Default path: "/".
sandbox.files.makeDir(path): Promise<void>
Create a directory (recursive).
sandbox.files.remove(path): Promise<void>
Delete a file or directory.
sandbox.files.exists(path): Promise<boolean>
Check if a path exists. Client-side wrapper — attempts a read and returns false on error.
Types
EntryInfo
Pty
Accessed viasandbox.pty.
sandbox.pty.create(opts?): Promise<PtySession>
Create an interactive terminal session.
PtySession
Image
Fluent, immutable builder for declarative sandbox images. Each method returns a newImage instance.
Image.base(): Image
Start from the default OpenSandbox environment (Ubuntu 22.04, Python, Node.js, build tools).
Builder Methods
image.toJSON(): ImageManifest
Returns the image manifest as a plain object.
image.cacheKey(): string
Computes a deterministic SHA-256 hash of the manifest for cache lookups.
Snapshots
Standalone class — not a property on Sandbox.new Snapshots(opts?)
snapshots.create(opts): Promise<SnapshotInfo>
Create a pre-built snapshot from a declarative image.
snapshots.list(): Promise<SnapshotInfo[]>
List all snapshots for the current organization.
snapshots.get(name): Promise<SnapshotInfo>
Get a snapshot by name.
snapshots.delete(name): Promise<void>
Delete a snapshot. Existing sandboxes created from it are not affected.
Types
SnapshotInfo
Secret Stores
SecretStore.create(opts)
Create a new secret store.
CreateSecretStoreOpts
required
Promise<SecretStoreInfo>
SecretStore.list(opts?)
List all secret stores.
Promise<SecretStoreInfo[]>
SecretStore.get(storeId, opts?)
Get a secret store by ID.
string
required
UUID of the secret store.
Promise<SecretStoreInfo>
SecretStore.update(storeId, opts)
Partial updates — only the fields you pass are changed.
string
required
UUID of the store to update.
UpdateSecretStoreOpts
required
Promise<SecretStoreInfo>
SecretStore.delete(storeId, opts?)
Deletes the store and all its secrets. Running sandboxes are not affected.
Promise<void>
SecretStore.setSecret(storeId, name, value, opts?)
Set a secret in a store. Secrets are encrypted at rest. The value is never returned by the API.
string
required
UUID of the secret store.
string
required
Secret name (used as the env var name in sandboxes).
string
required
Secret value (encrypted at rest, never returned by API).
Promise<void>
SecretStore.listSecrets(storeId, opts?)
Returns secret metadata only. Values are never exposed.
Promise<SecretEntryInfo[]>
SecretStore.deleteSecret(storeId, name, opts?)
Promise<void>
Creating a Sandbox with a Secret Store
Pass thesecretStore option to Sandbox.create() to inject the store’s secrets:
Types
SecretStoreInfo
SecretEntryInfo
Serverless Agents helpers
Sandbox and the OpenComputer client wrap the sandbox API and the /v3
Durable Agent Sessions API. The helpers in this section are different: they
call the Serverless Agents management API under
/api/managed-agents with an OpenComputer API key. Use them from trusted
server code only; the key must not reach a browser.
startSessionOnDocument(params): Promise<StartSessionOnDocumentResult>
Creates a memory document if it does not exist,
then a session bound to it, and reports both IDs and whether each already
existed. The two objects stay separate on the API; this helper does the two
calls in order and makes the pair converge on retry.
The steps, in order:
PUT /projects/<projectId>/memory/<resource>/documents/<documentId>withIf-None-Match: *and thedocumentbody.201means the document was created.412means it exists; the helper reads it withGETand leaves its content as it is. A404on that read means the ID was deleted and is reserved, which is an error, since a binding to it would fail admission.POST /sessionswithagentId: "<agent>@<environment>",source, andmemoryset to your further bindings plus{ [resource]: { scope: "document", id: documentId, access } }. TheIdempotency-Keyheader issessionIdempotencyKey(idempotencyKey).201created the session;200means the key had already created it.
Errors:
A retry with the same
idempotencyKey after a redeploy is a
ConflictError: the deployment is part of the session’s identity. Start
the new session under a new key.
sessionIdempotencyKey(idempotencyKey): Promise<string>
The Idempotency-Key the helper sends when creating the session: the
SHA-256 hex digest of opencomputer.memory.session, a NUL byte and your
key. Stable for a retry and distinct from any other use of the same caller
key. Use it to recognize the session-create key in your own requests or logs.
Memory types
The package exports the shapes of the memory management routes as types, for typing your own requests, the CLI’s--json output and opencomputer memory export files. They carry no behavior.