modal
    Preparing search index...

    Class Sandbox

    Sandboxes are secure, isolated containers in Modal that boot in seconds.

    Index

    Properties

    sandboxId: string

    Accessors

    Methods

    • Disconnect from the Sandbox, cleaning up local resources. The Sandbox continues running on Modal's infrastructure. After calling detach(), most operations on this Sandbox object will throw.

      Returns void

    • Get tags (key-value pairs) currently attached to this Sandbox from the server.

      Returns Promise<Record<string, string>>

    • Mount an Image at a path in the Sandbox filesystem.

      Parameters

      • path: string

        The path where the directory should be mounted

      • Optionalimage: Image

        Optional Image to mount. If undefined, mounts an empty directory.

      Returns Promise<void>

    • Check if the Sandbox has finished running.

      Returns null if the Sandbox is still running, else returns the exit code.

      Returns Promise<null | number>

    • Set tags (key-value pairs) on the Sandbox. Tags can be used to filter results in client.sandboxes.list.

      Parameters

      • tags: Record<string, string>

      Returns Promise<void>

    • Snapshots and creates a new Image from a directory in the running sandbox.

      The resulting Image is retained for ttlMs (default: 30 days), as a hard cutoff measured from creation — usage does not extend the lifetime. Pass ttlMs: null to retain indefinitely.

      The call has an overall timeoutMs budget (default: 55000). If it elapses before a snapshot completes, the call is cancelled and an error is thrown.

      Parameters

      Returns Promise<Image>

      Promise that resolves to an Image

    • Returns Promise<void>

    • Parameters

      • params: { wait: true }

      Returns Promise<number>

    • Get Tunnel metadata for the Sandbox.

      Raises SandboxTimeoutError if the tunnels are not available after the timeout.

      Parameters

      • timeoutMs: number = 50000

      Returns Promise<Record<number, Tunnel>>

      A dictionary of Tunnel objects which are keyed by the container port.

    • Unmounts an Image previously mounted at a path in the Sandbox filesystem.

      Parameters

      • path: string

        The mount path to unmount

      Returns Promise<void>

    • Wait until the Sandbox readiness probe reports the Sandbox is ready.

      This method only works for Sandboxes configured with a readiness probe.

      Parameters

      • timeoutMs: number = 300_000

        Maximum total time to wait, in milliseconds.

      Returns Promise<void>

      A promise that resolves once the Sandbox is ready.

      TimeoutError If readiness is not reported before timeoutMs.