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 git operations
- Run isolated code
- Access the internet
Example
Properties
Methods
betaPause()
Parameters
| Parameter | Type |
|---|---|
opts? | ConnectionOpts |
Returns
Promise<boolean>
Deprecated
Use Sandbox.pause instead.connect()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | SandboxConnectOpts | connection options. |
Returns
Promise<Sandbox>
A running sandbox instance
Example
createSnapshot()
snapshotId with Sandbox.create(snapshotId) to create a new sandbox from the snapshot.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | CreateSnapshotOpts | snapshot creation options including optional name and connection options. |
Returns
Promise<SnapshotInfo>
snapshot information including the snapshot ID.
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, "signal" | "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, "signal" | "requestTimeoutMs"> |
Returns
Promise<boolean>
true if the sandbox is running, false otherwise.
Example
kill()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | Pick<SandboxOpts, "signal" | "requestTimeoutMs"> | connection options. |
Returns
Promise<void>
listSnapshots()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | Omit<SnapshotListOpts, "sandboxId"> | list options. |
Returns
SnapshotPaginator
paginator for listing snapshots from this sandbox.
pause()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | ConnectionOpts | connection options. |
Returns
Promise<boolean>
sandbox ID that can be used to resume the sandbox.
Example
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, "signal" | "requestTimeoutMs"> | connection options. |
Returns
Promise<void>
updateNetwork()
Parameters
| Parameter | Type | Description |
|---|---|---|
network | SandboxNetworkUpdate | new network configuration. |
opts? | Pick<SandboxOpts, "signal" | "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.
betaPause()
Parameters
| Parameter | Type |
|---|---|
sandboxId | string |
opts? | SandboxApiOpts |
Returns
Promise<boolean>
Deprecated
Use SandboxApi.pause instead.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()
Call Signature
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
SandboxCall Signature
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
SandboxcreateSnapshot()
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID to create snapshot from. |
opts? | CreateSnapshotOpts | snapshot creation options including optional name and connection options. |
Returns
Promise<SnapshotInfo>
snapshot information including the snapshot name that can be used with Sandbox.create().
Parameters
| Parameter | Type | Description |
|---|---|---|
snapshotId | string | snapshot ID. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<boolean>
true if the snapshot was deleted, false if it was not found.
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<SandboxInfo>
sandbox information.
Deprecated
Use Sandbox.getInfo instead.Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<SandboxInfo>
sandbox information.
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.
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.
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | SandboxListOpts | connection options. |
Returns
SandboxPaginator
paginator for listing sandboxes.
listSnapshots()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | SnapshotListOpts | list options including filters and pagination. |
Returns
SnapshotPaginator
paginator for listing snapshots.
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.
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
timeoutMs | number | timeout in milliseconds. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<void>
Parameters
| Parameter | Type | Description |
|---|---|---|
sandboxId | string | sandbox ID. |
network | SandboxNetworkUpdate | new network configuration. |
opts? | SandboxApiOpts | connection options. |
Returns
Promise<void>