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 |
sandboxId | readonly | string | Unique identifier of the sandbox. |
Methods
downloadUrl()
Parameters
Parameter | Type | Description |
---|---|---|
path | string | path to the file to download. |
Returns
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
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 | the directory where to upload the file, defaults to user’s home directory. |
Returns
string
URL for uploading file.
connect()
Type Parameters
Type Parameter |
---|
S extends typeof Sandbox |
Parameters
Parameter | Type | Description |
---|---|---|
this | S | - |
sandboxId | string | sandbox ID. |
opts ? | Omit <SandboxOpts , "timeoutMs" | "metadata" | "envs" > | connection options. |
Returns
Promise
<InstanceType
<S
>>
sandbox instance for the existing sandbox.
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
Sandboxkill()
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 ? | SandboxApiOpts | connection options. |
Returns
Promise
<SandboxInfo
[]>
list of running sandboxes.
setTimeout()
Parameters
Parameter | Type | Description |
---|---|---|
sandboxId | string | sandbox ID. |
timeoutMs | number | timeout in milliseconds. |
opts ? | SandboxApiOpts | connection options. |
Returns
Promise
<void
>
Interfaces
SandboxOpts
Options for creating a new Sandbox.Properties
accessToken?
Default
apiKey?
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 orfalse
domain?
Default
E2B_DOMAIN // environment variable ore2b.dev
envs?
envs
argument when executing commands or code.
Default
logger?
Logger
interface—for example, console.