Skip to main content

Sandbox

Properties

Methods

betaPause()

Parameters
Returns
Promise<boolean>
Deprecated
Use Sandbox.pause instead.

connect()

Connect to a sandbox. If the sandbox is paused, it will be automatically resumed. Sandbox must be either running or be paused. With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
Parameters
Returns
Promise<Sandbox> A running sandbox instance
Example

createSnapshot()

Create a snapshot of the sandbox’s current state. The sandbox will be paused while the snapshot is being created. The snapshot can be used to create new sandboxes with the same filesystem and state. Snapshots are persistent and survive sandbox deletion. Use the returned snapshotId with Sandbox.create(snapshotId) to create a new sandbox from the snapshot.
Parameters
Returns
Promise<SnapshotInfo> snapshot information including the snapshot ID.
Throws
SandboxError with statusCode 400 when mode: 'filesystem' is requested but the feature is not enabled for the team (snapshot_filesystem_only_disabled), and with statusCode 409 when the sandbox’s node runs an orchestrator that predates the option (snapshot_filesystem_only_unsupported_node). A full memory snapshot still works in both cases; for 409, pause and resume the sandbox and retry.
Example

doubleClick()

Double left click on the mouse position.
Parameters
Returns
Promise<void>

downloadUrl()

Get the URL to download a file from the sandbox.
Parameters
Returns
Promise<string> URL for downloading file.

drag()

Drag the mouse from the given position to the given position.
Parameters
Returns
Promise<void>

fork()

Fork the sandbox. The sandbox is checkpointed in place (briefly paused, snapshotted with its full memory state, and resumed — its ID and expiration stay untouched) and count new sandboxes are created from that snapshot. All forks boot from the same snapshot, so the snapshot is captured once regardless of count. Each fork succeeds or fails independently — the returned array contains one entry per requested fork, either a running Sandbox instance or an Error describing why that fork failed to start (Promise.allSettled-style). Per-fork error codes map to the same error classes as other API errors (e.g. 429 to RateLimitError).
Parameters
Returns
Promise<(Sandbox | Error)[]> array with one entry per requested fork — a sandbox instance or an error.
Example

getApplicationWindows()

Get the window ID of the window with the given title.
Parameters
Returns
Promise<string[]> The ID of the window.

getCurrentWindowId()

Get the current window ID.
Returns
Promise<string> The ID of the current window.

getCursorPosition()

Get the current cursor position.
Returns
Promise<CursorPosition> A object with the x and y coordinates
Throws
Error if cursor position cannot be determined

getHost()

Get the host address for the specified sandbox port. You can then use this address to connect to the sandbox port from outside the sandbox via HTTP or WebSocket.
Parameters
Returns
string host address of the sandbox port.
Example

getInfo()

Get sandbox information like sandbox ID, template, metadata, started at/end at date.
Parameters
Returns
Promise<SandboxInfo> information about the sandbox

getMcpToken()

Get the MCP token for the sandbox.
Returns
Promise<undefined | string> MCP token for the sandbox, or undefined if MCP is not enabled.

getMcpUrl()

Get the MCP URL for the sandbox.
Returns
string MCP URL for the sandbox.

getMetrics()

Get the metrics of the sandbox.
Parameters
Returns
Promise<SandboxMetrics[]> List of sandbox metrics containing CPU, memory and disk usage information.

getScreenSize()

Get the current screen size.
Returns
Promise<ScreenSize> An ScreenSize object
Throws
Error if screen size cannot be determined

getWindowTitle()

Get the title of the window with the given ID.
Parameters
Returns
Promise<string> The title of the window.

isRunning()

Check if the sandbox is running.
Parameters
Returns
Promise<boolean> true if the sandbox is running, false otherwise.
Example

kill()

Kill the sandbox.
Parameters
Returns
Promise<boolean> true if the sandbox was killed, false if the sandbox was not found.

launch()

Launch an application.
Parameters
Returns
Promise<void>

leftClick()

Left click on the mouse position.
Parameters
Returns
Promise<void>

listSnapshots()

List all snapshots created from this sandbox.
Parameters
Returns
SnapshotPaginator paginator for listing snapshots from this sandbox.

middleClick()

Middle click on the mouse position.
Parameters
Returns
Promise<void>

mousePress()

Press the mouse button.
Parameters
Returns
Promise<void>

mouseRelease()

Release the mouse button.
Parameters
Returns
Promise<void>

moveMouse()

Move the mouse to the given coordinates.
Parameters
Returns
Promise<void>

open()

Open a file or a URL in the default application.
Parameters
Returns
Promise<void>

pause()

Pause a sandbox by its ID.
Parameters
Returns
Promise<boolean> true if the sandbox got paused, false if the sandbox was already paused.
Example

press()

Press a key.
Parameters
Returns
Promise<void>

rightClick()

Right click on the mouse position.
Parameters
Returns
Promise<void>

screenshot()

Call Signature
Take a screenshot and save it to the given name.
Returns
Promise<Uint8Array<ArrayBufferLike>> A Uint8Array bytes representation of the screenshot.
Call Signature
Take a screenshot and save it to the given name.
Parameters
Returns
Promise<Uint8Array<ArrayBufferLike>> A Uint8Array bytes representation of the screenshot.
Call Signature
Take a screenshot and save it to the given name.
Parameters
Returns
Promise<Blob> A Blob representation of the screenshot.
Call Signature
Take a screenshot and save it to the given name.
Parameters
Returns
Promise<ReadableStream<Uint8Array<ArrayBufferLike>>> A ReadableStream of bytes representation of the screenshot.

scroll()

Scroll the mouse wheel by the given amount.
Parameters
Returns
Promise<void>

setTimeout()

Set the timeout of the sandbox. This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to .setTimeout. Maximum time a sandbox can be kept alive is 24 hours (86_400_000 milliseconds) for Pro users and 1 hour (3_600_000 milliseconds) for Hobby users.
Parameters
Returns
Promise<void>

updateNetwork()

Update the network configuration of the sandbox. Replaces the current egress configuration atomically — fields that are omitted are cleared on the server.
Parameters
Returns
Promise<void>

uploadUrl()

Get the URL to upload a file to the sandbox. You have to send a POST request to this URL with the file as multipart/form-data.
Parameters
Returns
Promise<string> URL for uploading file.

wait()

Wait for the given amount of time.
Parameters
Returns
Promise<void>

waitAndVerify()

Wait for a command to return a specific result.
Parameters
Returns
Promise<boolean> true if the command returned the result within the timeout, otherwise false.

write()

Write the given text at the current cursor position.
Parameters
Returns
Promise<void>

betaPause()

Parameters
Returns
Promise<boolean>
Deprecated
Use SandboxApi.pause instead.

connect()

Connect to a sandbox. If the sandbox is paused, it will be automatically resumed. Sandbox must be either running or be paused. With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
Type Parameters
Parameters
Returns
Promise<InstanceType<S>> A running sandbox instance
Example

create()

Call Signature
Create a new sandbox from the default desktop sandbox template.
Type Parameters
Parameters
Returns
Promise<InstanceType<S>> sandbox instance for the new sandbox.
Example
Call Signature
Create a new sandbox from the specified sandbox template.
Type Parameters
Parameters
Returns
Promise<InstanceType<S>> sandbox instance for the new sandbox.
Example

createSnapshot()

Create a snapshot from a sandbox. The sandbox will be paused while the snapshot is being created. The snapshot can be used to create new sandboxes with the same state. The snapshot is a persistent image that survives sandbox deletion.
Parameters
Returns
Promise<SnapshotInfo> snapshot information including the snapshot name that can be used with Sandbox.create().
Throws
SandboxError with statusCode 400 when mode: 'filesystem' is requested but the feature is not enabled for the team (snapshot_filesystem_only_disabled), and with statusCode 409 when the sandbox’s node runs an orchestrator that predates the option (snapshot_filesystem_only_unsupported_node). A full memory snapshot still works in both cases; for 409, pause and resume the sandbox and retry.

deleteSnapshot()

Delete a snapshot.
Parameters
Returns
Promise<boolean> true if the snapshot was deleted, false if it was not found.

fork()

Fork a running sandbox specified by sandbox ID. The sandbox is checkpointed in place (briefly paused, snapshotted with its full memory state, and resumed — its ID and expiration stay untouched) and count new sandboxes are created from that snapshot. All forks boot from the same snapshot, so the snapshot is captured once regardless of count. Each fork succeeds or fails independently — the returned array contains one entry per requested fork, either a running Sandbox instance or an Error describing why that fork failed to start (Promise.allSettled-style). Per-fork error codes map to the same error classes as other API errors (e.g. 429 to RateLimitError).
Type Parameters
Parameters
Returns
Promise<(Error | InstanceType<S>)[]> array with one entry per requested fork — a sandbox instance or an error.
Example

getFullInfo()

Parameters
Returns
Promise<SandboxInfo> sandbox information.
Deprecated
Use Sandbox.getInfo instead.

getInfo()

Get sandbox information like sandbox ID, template, metadata, started at/end at date.
Parameters
Returns
Promise<SandboxInfo> sandbox information.

getMetrics()

Get the metrics of the sandbox.
Parameters
Returns
Promise<SandboxMetrics[]> List of sandbox metrics containing CPU, memory and disk usage information.

kill()

Kill the sandbox specified by sandbox ID.
Parameters
Returns
Promise<boolean> true if the sandbox was found and killed, false otherwise.

list()

List sandboxes. By default (no query.state set in opts), returns sandboxes in both running and paused states. To filter by state, pass opts.query.state = [...].
Parameters
Returns
SandboxPaginator a SandboxPaginator that yields pages of sandboxes (running and paused by default). Iterate pages via await paginator.nextItems() while paginator.hasNext is true.

listSnapshots()

List all snapshots.
Parameters
Returns
SnapshotPaginator paginator for listing snapshots.

pause()

Pause the sandbox specified by sandbox ID.
Parameters
Returns
Promise<boolean> true if the sandbox got paused, false if the sandbox was already paused.

setTimeout()

Set the timeout of the specified sandbox. After the timeout expires the sandbox will be automatically killed. This method can extend or reduce the sandbox timeout set when creating the sandbox or from the last call to Sandbox.setTimeout. Maximum time a sandbox can be kept alive is 24 hours (86_400_000 milliseconds) for Pro users and 1 hour (3_600_000 milliseconds) for Hobby users.
Parameters
Returns
Promise<void>

updateNetwork()

Update the network configuration of a running sandbox. Replaces the current egress configuration atomically — fields that are omitted are cleared on the server.
Parameters
Returns
Promise<void>

Interfaces

SandboxOpts

Configuration options for the Sandbox environment. SandboxOpts

Properties

allowInternetAccess?

Allow sandbox to access the internet. If set to False, it works the same as setting network denyOut to [0.0.0.0/0].

apiHeaders?

Additional headers to send with E2B API requests.

apiKey?

E2B API key to use for authentication.
Default

display?

Display identifier.

domain?

Domain to use for the API.
Default
E2B_DOMAIN // environment variable or e2b.app

dpi?

Dots per inch (DPI) setting for the display.

envs?

Custom environment variables for the sandbox. Used when executing commands and code in the sandbox. Can be overridden with the envs argument when executing commands or code.
Default

headers?

Additional headers to send with the request.
Deprecated
Use apiHeaders instead.

httpVersion?

HTTP version for requests to the E2B API and to sandboxes (commands, filesystem, PTY). '2' multiplexes streams over shared connections; '1.1' pins them to HTTP/1.1 with one connection per concurrent request — for example when an intermediary on the path retires or mishandles long-lived HTTP/2 connections. Only applies in Node.
Default
E2B_HTTP_VERSION // environment variable or '2'

iam?

Sandbox workload identity configuration. Providing a non-empty tokens map enables workload identity for the sandbox. Registered tokens are exposed to SandboxNetworkOpts.rules transform callbacks as iam.tokens.<name> placeholders, which the egress proxy resolves per request.
Example

lifecycle?

Sandbox lifecycle configuration.

logger?

Logger to use for logging messages. It can accept any object that implements Logger interface—for example, console.

mcp?

MCP server to enable in the sandbox
Default

metadata?

Custom metadata for the sandbox.
Default

network?

Sandbox network configuration

proxy?

Proxy URL to use for requests. In case of a sandbox it applies to all requests made to the returned sandbox.
Example

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default

resolution?

The screen resolution in pixels, specified as [width, height].

retries?

Number of control-plane API retries after a 429, 502 or 503 response or a failure to establish the connection (refused, DNS, unreachable host). Any other network error (dropped connection, opaque browser/Workers TypeError) is retried too. A 502 and those network errors are not retried for operations that create a resource (e.g. sandbox creation) or append to one (secret update), as the server may already have processed them. A 429 is retried only with a valid, non-negative integer delta-seconds Retry-After header (HTTP-date and malformed values are not retried). 502 and 503 honor such a Retry-After when present; otherwise they and connection failures use exponential backoff with jitter starting at 100 ms (capped at 10 s). Retry waits use a 60-second total limit when request timeouts are disabled.
Default

sandboxUrl?

Sandbox URL. Used for local development

secure?

Deprecated
Every sandbox secures envd access; this option is accepted for backward compatibility and ignored.

signal?

An optional AbortSignal that can be used to cancel the in-flight request. When the signal is aborted, the underlying fetch is aborted and the returned promise rejects with an AbortError.

template?

Sandbox template name or ID.
Default
‘base’ (or ‘mcp-gateway’ when mcp option is set)

timeoutMs?

Timeout for the sandbox in milliseconds. Maximum time a sandbox can be kept alive is 24 hours (86_400_000 milliseconds) for Pro users and 1 hour (3_600_000 milliseconds) for Hobby users.

validateApiKey?

Whether to validate the format of the E2B API key on the client side.
Deprecated
The API key format is no longer validated on the client side; this option has no effect.

volumeMounts?

Volume mounts for the sandbox. The keys are mount paths inside the sandbox and the values are either a Volume instance or a string representing the volume name.
Default