Skip to main content

Installation

npm install @opencomputer/sdk
import { Sandbox, Templates } from "@opencomputer/sdk";

Sandbox

Static Methods

Sandbox.create(opts?): Promise<Sandbox>

Create a new sandbox.
ParameterTypeDefaultDescription
templatestring"base"Template name
timeoutnumber300Idle timeout in seconds
apiKeystringenv varAPI key
apiUrlstringenv varAPI URL
envsRecord<string, string>Environment variables
metadataRecord<string, string>Arbitrary metadata
cpuCountnumberCPU cores (max 4)
memoryMBnumberMemory in MB (max 2048)
const sandbox = await Sandbox.create({ template: "my-stack", timeout: 600 });

Sandbox.connect(sandboxId, opts?): Promise<Sandbox>

Connect to an existing sandbox.
ParameterTypeDescription
sandboxIdstringSandbox ID
apiKeystringAPI key (optional)
apiUrlstringAPI URL (optional)
const sandbox = await Sandbox.connect("sb-abc123");

Sandbox.createFromCheckpoint(checkpointId, opts?): Promise<Sandbox>

Create a new sandbox from a checkpoint.
ParameterTypeDefaultDescription
checkpointIdstringCheckpoint ID (required)
timeoutnumber300Idle timeout
apiKeystringenv varAPI key
apiUrlstringenv varAPI URL
const forked = await Sandbox.createFromCheckpoint("cp-abc123");

Sandbox.createCheckpointPatch(checkpointId, opts): Promise<PatchResult>

Create a patch for a checkpoint.
ParameterTypeRequiredDescription
checkpointIdstringYesTarget checkpoint
scriptstringYesBash script
descriptionstringNoDescription
apiKeystringNoAPI key
apiUrlstringNoAPI URL
const result = await Sandbox.createCheckpointPatch("cp-abc", { script: "apt install -y curl" });

Sandbox.listCheckpointPatches(checkpointId, opts?): Promise<PatchInfo[]>

const patches = await Sandbox.listCheckpointPatches("cp-abc");

Sandbox.deleteCheckpointPatch(checkpointId, patchId, opts?): Promise<void>

await Sandbox.deleteCheckpointPatch("cp-abc", "pa-xyz");

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.
ParameterTypeDefaultDescription
timeoutnumber300Idle timeout after wake

sandbox.setTimeout(timeout): Promise<void>

Update the idle timeout.
ParameterTypeDescription
timeoutnumberNew timeout in seconds

sandbox.createCheckpoint(name): Promise<CheckpointInfo>

Create a named checkpoint.

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>

ParameterTypeRequiredDescription
portnumberYesContainer port (1–65535)
domainstringNoCustom domain
authConfigRecord<string, unknown>NoAuth configuration

sandbox.listPreviewURLs(): Promise<PreviewURLResult[]>

sandbox.deletePreviewURL(port): Promise<void>

Properties

PropertyTypeDescription
sandboxIdstringSandbox ID (readonly)
statusstringCurrent status (readonly)
agentAgentAgent sessions
execExecCommand execution
filesFilesystemFile operations
ptyPtyTerminal sessions
commandsExecDeprecated — alias for exec

Types

SandboxOpts

interface SandboxOpts {
  template?: string;
  timeout?: number;
  apiKey?: string;
  apiUrl?: string;
  envs?: Record<string, string>;
  metadata?: Record<string, string>;
  cpuCount?: number;
  memoryMB?: number;
}

CheckpointInfo

interface CheckpointInfo {
  id: string;
  sandboxId: string;
  orgId: string;
  name: string;
  sandboxConfig: object;
  status: string;       // "processing" | "ready" | "failed"
  sizeBytes: number;
  createdAt: string;
}

PatchInfo

interface PatchInfo {
  id: string;
  checkpointId: string;
  sequence: number;
  script: string;
  description: string;
  strategy: string;     // "on_wake"
  createdAt: string;
}

PatchResult

interface PatchResult {
  patch: PatchInfo;
}

PreviewURLResult

interface PreviewURLResult {
  id: string;
  sandboxId: string;
  orgId: string;
  hostname: string;
  customHostname?: string;
  port: number;
  cfHostnameId?: string;
  sslStatus: string;
  authConfig?: object;
  createdAt: string;
}

Agent

Accessed via sandbox.agent.

sandbox.agent.start(opts?): Promise<AgentSession>

Start an agent session.
ParameterTypeDescription
promptstringInitial prompt
modelstringClaude model
systemPromptstringSystem prompt
allowedToolsstring[]Restrict tools
permissionModestringPermission mode
maxTurnsnumberMax turns (default: 50)
cwdstringWorking directory
mcpServersRecord<string, McpServerConfig>MCP servers
resumestringResume session ID
onEvent(event: AgentEvent) => voidEvent callback
onError(data: string) => voidStderr callback
onExit(exitCode: number) => voidExit callback
onScrollbackEnd() => voidScrollback done callback
const session = await sandbox.agent.start({
  prompt: "Build a todo app",
  onEvent: (e) => console.log(e.type),
});

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

MemberTypeDescription
sessionIdstringSession ID
donePromise<number>Resolves with exit code
sendPrompt(text)methodSend follow-up prompt
interrupt()methodInterrupt current turn
configure(config)methodUpdate agent configuration
kill(signal?)Promise<void>Kill agent process
close()methodClose WebSocket

Types

AgentEvent

interface AgentEvent {
  type: string;
  [key: string]: unknown;
}

McpServerConfig

interface McpServerConfig {
  command: string;
  args?: string[];
  env?: Record<string, string>;
}

Exec

Accessed via sandbox.exec.

sandbox.exec.run(command, opts?): Promise<ProcessResult>

Run a command synchronously.
ParameterTypeDefaultDescription
commandstringShell command (required)
timeoutnumber60Timeout in seconds
envRecord<string, string>Environment variables
cwdstringWorking directory
const result = await sandbox.exec.run("npm test", { cwd: "/app" });

sandbox.exec.start(command, opts?): Promise<ExecSession>

Start a long-running command with streaming.
ParameterTypeDescription
commandstringCommand (required)
argsstring[]Arguments
envRecord<string, string>Environment variables
cwdstringWorking directory
timeoutnumberTimeout in seconds
maxRunAfterDisconnectnumberSeconds to keep running after disconnect
onStdout(data: Uint8Array) => voidStdout callback
onStderr(data: Uint8Array) => voidStderr callback
onExit(exitCode: number) => voidExit callback
const session = await sandbox.exec.start("node server.js", {
  onStdout: (data) => process.stdout.write(data),
});

sandbox.exec.attach(sessionId, opts?): Promise<ExecSession>

Reconnect to a running exec session.
ParameterTypeDescription
sessionIdstringSession ID (required)
onStdout(data: Uint8Array) => voidStdout callback
onStderr(data: Uint8Array) => voidStderr callback
onExit(exitCode: number) => voidExit callback
onScrollbackEnd() => voidScrollback replay done

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

MemberTypeDescription
sessionIdstringSession ID
donePromise<number>Resolves with exit code
sendStdin(data)methodSend input (string or Uint8Array)
kill(signal?)Promise<void>Kill process
close()methodClose WebSocket

Types

ProcessResult

interface ProcessResult {
  exitCode: number;
  stdout: string;
  stderr: string;
}

ExecSessionInfo

interface ExecSessionInfo {
  sessionID: string;
  sandboxID: string;
  command: string;
  args: string[];
  running: boolean;
  exitCode?: number;
  startedAt: string;
  attachedClients: number;
}

Filesystem

Accessed via sandbox.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

interface EntryInfo {
  name: string;
  isDir: boolean;
  path: string;
  size: number;
}

Pty

Accessed via sandbox.pty.

sandbox.pty.create(opts?): Promise<PtySession>

Create an interactive terminal session.
ParameterTypeDefaultDescription
colsnumber80Terminal columns
rowsnumber24Terminal rows
onOutput(data: Uint8Array) => voidOutput callback

PtySession

MemberTypeDescription
sessionIdstringSession ID
send(data)methodSend input (string or Uint8Array)
close()methodClose the PTY

Templates

Standalone class — not a property on Sandbox.

new Templates(apiUrl, apiKey)

import { Templates } from "@opencomputer/sdk";

const templates = new Templates("https://app.opencomputer.dev", apiKey);

templates.build(name, dockerfile): Promise<TemplateInfo>

Build a template from a Dockerfile string.

templates.list(): Promise<TemplateInfo[]>

List all templates.

templates.get(name): Promise<TemplateInfo>

Get a template by name.

templates.delete(name): Promise<void>

Delete a template.

Types

TemplateInfo

interface TemplateInfo {
  templateID: string;
  name: string;
  tag: string;
  status: string;  // "ready" | "building" | "error"
}