Classes
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
commands
Module for running commands in the sandboxreadonly
commands:Commands
Defined in
sandbox/index.ts:74files
Module for interacting with the sandbox filesystemreadonly
files:Filesystem
Defined in
sandbox/index.ts:70pty
Module for interacting with the sandbox pseudo-terminalsreadonly
pty:Pty
Defined in
sandbox/index.ts:78sandboxId
Unique identifier of the sandbox.readonly
sandboxId:string
Defined in
sandbox/index.ts:83Methods
downloadUrl()
downloadUrl(Get the URL to download a file from the sandbox.path
):string
Parameters
• path:string
path to the file to download.
Returns
string
URL for downloading file.
Defined in
sandbox/index.ts:339getHost()
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.port
):string
Parameters
• port:number
number of the port in the sandbox.
Returns
string
host address of the sandbox port.
Example
Defined in
sandbox/index.ts:259kill()
kill(Kill the sandbox.opts
?):Promise
<void
>
Parameters
• opts?:Pick
<SandboxOpts
, "requestTimeoutMs"
>
connection options.
Returns
Promise
<void
>
Defined in
sandbox/index.ts:310setTimeout()
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 totimeoutMs
,opts
?):Promise
<void
>
.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
• timeoutMs:number
timeout in milliseconds.
• opts?: Pick
<SandboxOpts
, "requestTimeoutMs"
>
connection options.
Returns
Promise
<void
>
Defined in
sandbox/index.ts:290uploadUrl()
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.path
?):string
Parameters
• path?:string
the directory where to upload the file, defaults to user’s home directory.
Returns
string
URL for uploading file.
Defined in
sandbox/index.ts:328connect()
Connect to an existing sandbox. With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).static
connect<S
>(this
,sandboxId
,opts
?):Promise
<InstanceType
<S
>>
Type Parameters
• S extends typeofSandbox
Parameters
• 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
Defined in
sandbox/index.ts:209create()
create(this, opts)
Create a new sandbox from the defaultstatic
create<S
>(this
,opts
?):Promise
<InstanceType
<S
>>
base
sandbox template.
Type Parameters
• S extends typeofSandbox
Parameters
• this:S
• opts?: SandboxOpts
connection options.
Returns
Promise
<InstanceType
<S
>>
sandbox instance for the new sandbox.
Example
Constructs
SandboxDefined in
sandbox/index.ts:143create(this, template, opts)
Create a new sandbox from the specified sandbox template.static
create<S
>(this
,template
,opts
?):Promise
<InstanceType
<S
>>
Type Parameters
• S extends typeofSandbox
Parameters
• 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
SandboxDefined in
sandbox/index.ts:162kill()
Kill the sandbox specified by sandbox ID.static
kill(sandboxId
,opts
?):Promise
<boolean
>
Parameters
• sandboxId:string
sandbox ID.
• opts?: SandboxApiOpts
connection options.
Returns
Promise
<boolean
>
true
if the sandbox was found and killed, false
otherwise.
Defined in
sandbox/sandboxApi.ts:55list()
List all running sandboxes.static
list(opts
?):Promise
<SandboxInfo
[]>
Parameters
• opts?:SandboxApiOpts
connection options.
Returns
Promise
<SandboxInfo
[]>
list of running sandboxes.
Defined in
sandbox/sandboxApi.ts:90setTimeout()
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.static
setTimeout(sandboxId
,timeoutMs
,opts
?):Promise
<void
>
Parameters
• sandboxId:string
sandbox ID.
• timeoutMs: number
timeout in milliseconds.
• opts?: SandboxApiOpts
connection options.
Returns
Promise
<void
>
Defined in
sandbox/sandboxApi.ts:129Interfaces
SandboxOpts
Options for creating a new Sandbox.Properties
accessToken?
E2B access token to use for authentication.optional
accessToken:string
Default
Defined in
connectionConfig.ts:24apiKey?
E2B API key to use for authentication.optional
apiKey:string
Default
Defined in
connectionConfig.ts:18debug?
optional
debug:boolean
Internal
If true the SDK starts in the debug mode and connects to the local envd API server.
Default
E2B_DEBUG // environment variable orfalse
Defined in
connectionConfig.ts:36domain?
Domain to use for the API.optional
domain:string
Default
E2B_DOMAIN // environment variable ore2b.dev
Defined in
connectionConfig.ts:30envs?
Custom environment variables for the sandbox. Used when executing commands and code in the sandbox. Can be overridden with theoptional
envs:Record
<string
,string
>
envs
argument when executing commands or code.
Default
Defined in
sandbox/index.ts:32logger?
Logger to use for logging messages. It can accept any object that implementsoptional
logger:Logger
Logger
interface—for example, console.
Defined in
connectionConfig.ts:46metadata?
Custom metadata for the sandbox.optional
metadata:Record
<string
,string
>
Default
Defined in
sandbox/index.ts:23requestTimeoutMs?
Timeout for requests to the API in milliseconds.optional
requestTimeoutMs:number
Default
Defined in
connectionConfig.ts:42timeoutMs?
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.optional
timeoutMs:number