For the complete documentation index, see llms.txt. This page is also available as Markdown.

compute.instances

Overview

Core methods for creating, destroying, listing, and retrieving sandbox instances.

Deprecated alias: compute.sandbox still works as an alias for compute.instances — prefer compute.instances in new code.


create(options?)

Create a new compute sandbox instance.

Parameters:

  • options (CreateInstanceOptions, optional): Configuration options for sandbox creation

    • sizeClass (xs | sm | md | lg | xl | 2xl, optional): Exact standard CPU/RAM request; see Sandbox sizes for mappings and conflicts

    • timeout (number, optional): Provider-specific sandbox lifetime/idle policy in milliseconds; separate from a command timeout

    • ephemeral (boolean, optional): Selects the ephemeral (true) or persistent (false) surface on providers offering both; unset uses provider config

    • templateId (string, optional): Provider-agnostic template or image identifier to boot from

    • snapshotId (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 sandbox

    • envs (Record<string, string>, optional): Environment variables to set in the sandbox

    • signal (AbortSignal, optional): Cancels sandbox creation and cleans up an orphaned sandbox if the signal aborts

    • name, namespace, directory (string, optional): Provider-specific naming/placement hints

    • Additional provider-specific properties are passed through (e.g. domain for E2B)

Returns: Promise<InstanceInterface> - New sandbox instance ready for code execution and commands

Instance properties:

  • instanceId (string): Unique identifier for the sandbox

  • provider (string): Provider hosting the sandbox (e.g., 'e2b', 'modal', 'vercel')

  • filesystem (InstanceFileSystem): File system operations interface

  • Core methods: runCommand(), getInfo(), getUrl(), destroy()

  • See Instance API Reference for complete interface documentation

CreateInstanceOptions interface:

Examples:

Notes:

  • Configure your provider by importing and initializing a provider package (e.g., @computesdk/e2b) with your credentials

  • Each call creates a new sandbox instance with a unique instanceId

  • timeout is not a universal auto-delete guarantee: providers may use a lifetime, auto-pause/idle timeout, or reject an unsupported deadline. Check the provider page; runCommand(..., { timeout }) is a separate command deadline.

  • Read provider.instances.pause?.createOptions and provider.snapshot?.capabilities?.createOptions before creating an instance that must pause or snapshot. The framework exposes these requirements but does not automatically apply them.

  • Direct provider managers may expose provider.instances.lifetime (defaultMs, maxMs, extendable). An absent descriptor does not establish the vendor's default or limit. See Instance lifecycle for pause/resume and extension.

  • Restore with snapshotId on the same provider that made the snapshot. In multi-provider mode, explicitly select that provider for the new instance; a snapshot ID is not a portable image.

  • The templateId parameter is provider-specific (refers to templates, images, or runtime environments)

  • Environment variables set via envs are available to all commands and code executed in the sandbox

  • Throws an error if the provider is missing required credentials (e.g., API key)


destroy(instanceId)

Destroy a sandbox and clean up all associated resources.

Parameters:

  • instanceId (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, or compute.instances.destroy(instanceId) with the ID

  • Destroying 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 finally blocks or cleanup handlers to ensure sandboxes are destroyed even if errors occur

  • All sandbox data and files are permanently lost after destruction


getById(instanceId)

Retrieve an existing sandbox instance by its unique identifier.

Parameters:

  • instanceId (string, required): Unique identifier of the sandbox to retrieve

Returns: Promise<InstanceInterface | null> - Sandbox instance if found, or null if the sandbox doesn't exist

Instance properties:

  • instanceId (string): Unique identifier for the sandbox

  • provider (string): Provider hosting the sandbox

  • filesystem (InstanceFileSystem): File system operations interface

  • Core methods: runCommand(), getInfo(), getUrl(), destroy()

  • See Instance API Reference for complete interface documentation

Examples:

Notes:

  • Returns null for 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?