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
Example
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
commands | readonly | Commands | Module for running commands in the sandbox |
files | readonly | Filesystem | Module for interacting with the sandbox filesystem |
pty | readonly | Pty | Module for interacting with the sandbox pseudo-terminals |
sandboxDomain | readonly | string | Domain where the sandbox is hosted. |
sandboxId | readonly | string | Unique identifier of the sandbox. |
trafficAccessToken? | readonly | string | Traffic access token for accessing sandbox services with restricted public traffic. |
Methods
betaPause()
Beta
This feature is in beta and may change in the future.
Pause a sandbox by its ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | ConnectionOpts | connection options. |
Returns
Promise<boolean>
sandbox ID that can be used to resume the sandbox.
connect()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | SandboxBetaCreateOpts | connection options. |
Returns
Promise<Sandbox>
A running sandbox instance
Example
downloadUrl()
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | path to the file in the sandbox. |
opts? | SandboxUrlOpts | download url options. |
Returns
Promise<string>
URL for downloading file.
getHost()
Parameters
| Parameter | Type | Description |
|---|---|---|
port | number | number of the port in the sandbox. |
Returns
string
host address of the sandbox port.
Example
getInfo()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | Pick<SandboxOpts, "requestTimeoutMs"> | connection options. |
Returns
Promise<SandboxInfo>
information about the sandbox
getMcpToken()
Returns
Promise<undefined | string>
MCP token for the sandbox, or undefined if MCP is not enabled.
getMcpUrl()
Returns
string
MCP URL for the sandbox.
getMetrics()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | SandboxMetricsOpts | connection options. |
Returns
Promise<SandboxMetrics[]>
List of sandbox metrics containing CPU, memory and disk usage information.
isRunning()
Parameters
| Parameter | Type |
|---|---|
opts? | Pick<ConnectionOpts, "requestTimeoutMs"> |
Returns
Promise<boolean>
true if the sandbox is running, false otherwise.
Example
kill()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | Pick<SandboxOpts, "requestTimeoutMs"> | connection options. |
Returns
Promise<void>
setTimeout()
.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
| Parameter | Type | Description |
|---|---|---|
timeoutMs | number | timeout in milliseconds. |
opts? | Pick<SandboxOpts, "requestTimeoutMs"> | connection options. |
Returns
Promise<void>
uploadUrl()
Parameters
| Parameter | Type | Description |
|---|---|---|
path? | string | path to the file in the sandbox. |
opts? | SandboxUrlOpts | download url options. |
Returns
Promise<string>
URL for uploading file.
betaCreate()
betaCreate(this, opts)
Beta
This feature is in beta and may change in the future.
Create a new sandbox from the default base sandbox template.
Type Parameters
| Type Parameter |
|---|
S extends typeof Sandbox |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | S | - |
opts? | SandboxBetaCreateOpts | connection options. |
Returns
Promise<InstanceType<S>>
sandbox instance for the new sandbox.
Example
Constructs
SandboxbetaCreate(this, template, opts)
Beta
This feature is in beta and may change in the future.
Create a new sandbox from the specified sandbox template.
Type Parameters
| Type Parameter |
|---|
S extends typeof Sandbox |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | S | - |
template | string | sandbox template name or ID. |
opts? | SandboxBetaCreateOpts | connection options. |
Returns
Promise<InstanceType<S>>
sandbox instance for the new sandbox.
Example
Constructs
SandboxbetaPause()
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<boolean>
true if the sandbox got paused, false if the sandbox was already paused.
connect()
Type Parameters
| Type Parameter |
|---|
S extends typeof Sandbox |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | S | - |
sandboxId | string | sandbox ID. |
opts? | SandboxConnectOpts | connection options. |
Returns
Promise<InstanceType<S>>
A running sandbox instance
Example
create()
create(this, opts)
base sandbox template.
Type Parameters
| Type Parameter |
|---|
S extends typeof Sandbox |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | S | - |
opts? | SandboxOpts | connection options. |
Returns
Promise<InstanceType<S>>
sandbox instance for the new sandbox.
Example
Constructs
Sandboxcreate(this, template, opts)
Type Parameters
| Type Parameter |
|---|
S extends typeof Sandbox |
Parameters
| Parameter | Type | Description |
|---|---|---|
this | S | - |
template | string | sandbox template name or ID. |
opts? | SandboxOpts | connection options. |
Returns
Promise<InstanceType<S>>
sandbox instance for the new sandbox.
Example
Constructs
SandboxgetFullInfo()
Parameters
| Parameter | Type |
|---|---|
sandboxId | string |
opts? | SandboxApiOpts |
Returns
Promise<object>
| Name | Type | Default value |
|---|---|---|
cpuCount | number | res.data.cpuCount |
endAt | Date | - |
envdAccessToken | undefined | string | res.data.envdAccessToken |
envdVersion | string | res.data.envdVersion |
memoryMB | number | res.data.memoryMB |
metadata | object | - |
name? | string | res.data.alias |
sandboxDomain | undefined | string | - |
sandboxId | string | res.data.sandboxID |
startedAt | Date | - |
state | "running" | "paused" | res.data.state |
templateId | string | res.data.templateID |
getInfo()
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<SandboxInfo>
sandbox information.
getMetrics()
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
opts? | SandboxMetricsOpts | sandbox metrics options. |
Returns
Promise<SandboxMetrics[]>
List of sandbox metrics containing CPU, memory and disk usage information.
kill()
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<boolean>
true if the sandbox was found and killed, false otherwise.
list()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | SandboxListOpts | connection options. |
Returns
SandboxPaginator
paginator for listing sandboxes.
setTimeout()
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
timeoutMs | number | timeout in milliseconds. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<void>