Sandbox.create(opts?)body templatestringdefault: basebody timeoutnumberdefault: 300body apiKeystringOPENCOMPUTER_API_KEY env var)body apiUrlstringOPENCOMPUTER_API_URL env var)body envsRecord<string, string>body metadataRecord<string, string>body burstbooleanbody cpuCountnumberbody memoryMBnumberbody secretStorestringbody imageImagebody snapshotstringbody onBuildLog(log: string) => voidimage)Promise<Sandbox>1const sandbox = await Sandbox.create({ template: "my-stack", timeout: 600 });
1234const sandbox = await Sandbox.create({ burst: true, timeout: 300, });
Sandbox.connect(sandboxId, opts?)body sandboxIdstringrequiredbody apiKeystringbody apiUrlstringPromise<Sandbox>1const sandbox = await Sandbox.connect("sb-abc123");
Sandbox.createFromCheckpoint(checkpointId, opts?)body checkpointIdstringrequiredbody timeoutnumberdefault: 300Promise<Sandbox>1const forked = await Sandbox.createFromCheckpoint("cp-abc123");
Sandbox.createCheckpointPatch(checkpointId, opts)body checkpointIdstringrequiredbody scriptstringrequiredbody descriptionstringPromise<PatchResult>1const result = await Sandbox.createCheckpointPatch("cp-abc", { script: "apt install -y curl" });
sandbox.isRunning()Promise<boolean>sandbox.hibernate()Promise<void>sandbox.wake(opts?)body timeoutnumberdefault: 300Promise<void>sandbox.setTimeout(timeout)body timeoutnumberrequiredPromise<void>sandbox.createCheckpoint(name, opts?)body namestringrequiredbody opts.retentionPolicyobject{ mode: "delete_oldest", maxCount: 10 } for
full checkpoints or { mode: "delete_oldest", maxCount: 100 } with
kind: "disk_only" to delete the oldest eligible checkpoint of the same type
before creating a new one.Promise<CheckpointInfo>sandbox.listCheckpoints()Promise<CheckpointInfo[]>sandbox.restoreCheckpoint(checkpointId)Promise<void>sandbox.deleteCheckpoint(checkpointId)Promise<void>sandbox.getPreviewDomain(port)body portnumberrequiredstring (e.g., sb-abc123-p3000.workers.opencomputer.dev)12const domain = sandbox.getPreviewDomain(3000); console.log(`https://${domain}`);
sandbox.downloadUrl(path, opts?)body pathstringrequiredbody opts.expiresInnumberdefault: 3600Promise<string>sandbox.uploadUrl(path, opts?)body pathstringrequiredbody opts.expiresInnumberdefault: 3600Promise<string>sandbox.createPreviewURL(opts)body portnumberrequiredbody domainstringbody authConfigRecord<string, unknown>Promise<PreviewURLResult>sandbox.listPreviewURLs()Promise<PreviewURLResult[]>sandbox.getAllowedHosts()secretStore option return an empty allowlist with secretStore undefined — the sandbox has no per-store egress restriction.Promise<AllowedHostsInfo>123const info = await sandbox.getAllowedHosts(); console.log(info.egressAllowlist); // ['api.openai.com', 'api.anthropic.com'] console.log(info.perSecretAllowedHosts); // { 'OPENAI_API_KEY': ['api.openai.com'] }
AllowedHostsInfo:body sandboxIDstringbody secretStorestringsecretStore option.body baseSecretStorestringsecretStore on top of an inherited one. Empty for sandboxes created from scratch and for forks without an override.body egressAllowliststring[]body perSecretAllowedHostsRecord<string, string[]>body sandboxIdstringbody statusstringbody domainstringsb-abc123-p80.workers.opencomputer.dev). Returns empty string if sandbox domain is not configured.body agentSandboxAgentbody execExecbody filesFilesystembody ptyPtybody commandsExecexec1234567891011121314interface SandboxOpts { template?: string; timeout?: number; apiKey?: string; apiUrl?: string; envs?: Record<string, string>; metadata?: Record<string, string>; cpuCount?: number; memoryMB?: number; secretStore?: string; image?: Image; snapshot?: string; onBuildLog?: (log: string) => void; }
12345678910interface CheckpointInfo { id: string; sandboxId: string; orgId: string; name: string; sandboxConfig: object; status: string; // "processing" | "ready" | "failed" sizeBytes: number; createdAt: string; }
12345678910111213interface PatchInfo { id: string; checkpointId: string; sequence: number; script: string; description: string; strategy: string; // "on_wake" createdAt: string; } interface PatchResult { patch: PatchInfo; }
123456789101112interface PreviewURLResult { id: string; sandboxId: string; orgId: string; hostname: string; customHostname?: string; port: number; cfHostnameId?: string; sslStatus: string; authConfig?: object; createdAt: string; }