Skip to main content

Sandbox

E2B cloud sandbox is a secure and isolated cloud environment. The sandbox allows you to:
  • Access Linux OS
  • Create, list, and delete files and directories
  • Run commands
  • Run isolated code
  • Access the internet
Check docs here. Use Sandbox.create to create a new sandbox.

Example

Properties

Methods

downloadUrl()

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

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

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<void>

setTimeout()

Set the timeout of the 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 .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>

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
string URL for uploading file.

connect()

Connect to an existing sandbox. 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>> sandbox instance for the existing sandbox.
Example

create()

create(this, opts)
Create a new sandbox from the default base sandbox template.
Type Parameters
Parameters
Returns
Promise<InstanceType<S>> sandbox instance for the new sandbox.
Example
Constructs
Sandbox
create(this, template, opts)
Create a new sandbox from the specified sandbox template.
Type Parameters
Parameters
Returns
Promise<InstanceType<S>> sandbox instance for the new sandbox.
Example
Constructs
Sandbox

kill()

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

list()

List all running sandboxes.
Parameters
Returns
Promise<SandboxInfo[]> list of running sandboxes.

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>

Interfaces

SandboxOpts

Options for creating a new Sandbox.

Properties

accessToken?

E2B access token to use for authentication.
Default

apiKey?

E2B API key to use for authentication.
Default

debug?

Internal If true the SDK starts in the debug mode and connects to the local envd API server.
Default
E2B_DEBUG // environment variable or false

domain?

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

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

logger?

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

metadata?

Custom metadata for the sandbox.
Default

requestTimeoutMs?

Timeout for requests to the API in milliseconds.
Default

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.
Default