compute.sandbox
Overview
Core methods for creating, destroying, listing, and retrieving sandbox instances.
create(options?)
Create a new compute sandbox instance.
Parameters:
options(CreateSandboxOptions, optional): Configuration options for sandbox creationtimeout(number, optional): Sandbox execution timeout in millisecondstemplateId(string, optional): Provider-agnostic template or image identifier to boot fromsnapshotId(string, optional): Snapshot ID to restore from; each provider maps this to its native concept (E2B template, Daytona snapshot, Modal image, etc.)metadata(Record<string, any>, optional): Custom metadata to attach to the sandboxenvs(Record<string, string>, optional): Environment variables to set in the sandboxsignal(AbortSignal, optional): Cancels sandbox creation and cleans up an orphaned sandbox if the signal abortsname,namespace,directory(string, optional): Provider-specific naming/placement hintsAdditional provider-specific properties are passed through (e.g.
domainfor E2B)
Returns: Promise<Sandbox> - New sandbox instance ready for code execution and commands
Sandbox instance properties:
sandboxId(string): Unique identifier for the sandboxprovider(string): Provider hosting the sandbox (e.g., 'e2b', 'modal', 'vercel')filesystem(SandboxFileSystem): File system operations interfaceCore methods:
runCommand(),getInfo(),getUrl(),destroy()See Sandbox API Reference for complete interface documentation
CreateSandboxOptions interface:
Examples:
Notes:
Configure your provider by importing and initializing a provider package (e.g.,
@computesdk/e2b) with your credentialsEach call creates a new sandbox instance with a unique
sandboxIdThe
timeoutoption sets maximum sandbox lifetime; sandboxes auto-terminate after this periodThe
templateIdparameter is provider-specific (refers to templates, images, or runtime environments)Environment variables set via
envsare available to all commands and code executed in the sandboxThrows an error if the provider is missing required credentials (e.g., API key)
destroy(sandboxId)
Destroy a sandbox and clean up all associated resources.
Parameters:
sandboxId(string, required): Unique identifier of the sandbox to destroy
Returns: Promise<void> - Resolves when sandbox is successfully destroyed
⚠️ CAUTION: Destroying a sandbox is a permanent operation. All data, files, and running processes in the sandbox will be irreversibly deleted.
Examples:
Notes:
You can call
sandbox.destroy()directly on the sandbox instance, orcompute.sandbox.destroy(sandboxId)with the IDDestroying a sandbox terminates all running processes and releases all allocated resources
This operation is idempotent - calling destroy on an already-destroyed sandbox succeeds without error
Best practice: Use
finallyblocks or cleanup handlers to ensure sandboxes are destroyed even if errors occurAll sandbox data and files are permanently lost after destruction
getById(sandboxId)
Retrieve an existing sandbox instance by its unique identifier.
Parameters:
sandboxId(string, required): Unique identifier of the sandbox to retrieve
Returns: Promise<Sandbox | null> - Sandbox instance if found, or null if the sandbox doesn't exist
Sandbox instance properties:
sandboxId(string): Unique identifier for the sandboxprovider(string): Provider hosting the sandboxfilesystem(SandboxFileSystem): File system operations interfaceCore methods:
runCommand(),getInfo(),getUrl(),destroy()See Sandbox API Reference for complete interface documentation
Examples:
Notes:
Returns
nullfor non-existent or destroyed sandboxes (does not throw errors)Retrieved sandboxes have full functionality identical to newly created sandboxes
Useful for reconnecting to long-lived sandboxes or implementing persistent sandbox patterns
Sandbox IDs can be stored and used to reconnect later across application restarts
list()
Retrieve a list of your active sandboxes from your provider.
Notes:
Returns all active sandboxes for the configured provider
Provider support for listing sandboxes varies — check your provider's documentation for details
Last updated
Was this helpful?