await Sandbox.create(...)body templatestrdefault: basebody timeoutintdefault: 300body api_keystrOPENCOMPUTER_API_KEY env var)body api_urlstrOPENCOMPUTER_API_URL env var)body envsdict[str, str]body metadatadict[str, str]body burstboolbody imageImagebody snapshotstrbody on_build_logCallable[[str], None]image)Sandbox1sandbox = await Sandbox.create(template="my-stack", timeout=600)
1234sandbox = await Sandbox.create( burst=True, timeout=300, )
await Sandbox.connect(sandbox_id, ...)body sandbox_idstrrequiredSandbox1sandbox = await Sandbox.connect("sb-abc123")
await Sandbox.create_from_checkpoint(checkpoint_id, ...)body checkpoint_idstrrequiredbody timeoutintdefault: 300Sandbox1forked = await Sandbox.create_from_checkpoint("cp-abc123")
await Sandbox.create_checkpoint_patch(checkpoint_id, script, ...)body checkpoint_idstrrequiredbody scriptstrrequiredbody descriptionstrdictawait Sandbox.list_checkpoint_patches(checkpoint_id, ...)list[dict]1234async with await Sandbox.create() as sandbox: result = await sandbox.exec.run("echo hello") print(result.stdout) # sandbox.kill() called automatically
await sandbox.is_running()boolawait sandbox.set_timeout(timeout)body timeoutintrequiredNoneawait sandbox.create_checkpoint(name, kind=None, retention_policy=None)body retention_policydict{"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.dictawait sandbox.list_checkpoints()list[dict]await sandbox.restore_checkpoint(checkpoint_id)Noneawait sandbox.delete_checkpoint(checkpoint_id)Noneawait sandbox.download_url(path, *, expires_in=3600)body pathstrrequiredbody expires_inintdefault: 3600strawait sandbox.upload_url(path, *, expires_in=3600)body pathstrrequiredbody expires_inintdefault: 3600strawait sandbox.create_preview_url(port, domain?, auth_config?)body portintrequiredbody domainstrbody auth_configdictdictawait sandbox.list_preview_urls()list[dict]await sandbox.delete_preview_url(port)Noneawait sandbox.get_allowed_hosts()secret_store option return an empty allowlist with secretStore omitted — the sandbox has no per-store egress restriction.dict with the shape:123456789{ "sandboxID": "sb-...", "secretStore": "my-store", # omitted if no store "baseSecretStore": "parent-store", # omitted unless this is a layered fork "egressAllowlist": ["api.openai.com", ...], "perSecretAllowedHosts": { "OPENAI_API_KEY": ["api.openai.com"], }, }
secret_store on top of an inherited one, egressAllowlist is the union of both stores' allowlists (matches what the runtime proxy enforces) and baseSecretStore is populated with the inherited parent's name. For sandboxes with a single store (or none), baseSecretStore is omitted.123info = await sandbox.get_allowed_hosts() print(info["egressAllowlist"]) # ['api.openai.com', 'api.anthropic.com'] print(info["perSecretAllowedHosts"]) # {'OPENAI_API_KEY': ['api.openai.com']}
await sandbox.close()hibernate() / wake()cpuCount / memoryMB on createbody sandbox_idstrbody statusstrbody agentAgentbody execExecbody filesFilesystembody ptyPtybody commandsExecexec