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
Methods
createCodeContext()
Parameters
| Parameter | Type | Description |
|---|---|---|
opts? | CreateCodeContextOpts | options for creating the context. |
Returns
Promise<Context>
context object.
listCodeContexts()
Returns
Promise<Context[]>
list of contexts.
removeCodeContext()
Parameters
| Parameter | Type | Description |
|---|---|---|
context | string | Context | context to remove. |
Returns
Promise<void>
void.
restartCodeContext()
Parameters
| Parameter | Type | Description |
|---|---|---|
context | string | Context | context to restart. |
Returns
Promise<void>
void.
runCode()
runCode(code, opts)
language or context option to run the code as a different language or in a different Context.
You can reference previously defined variables, imports, and functions in the code.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | string | code to execute. |
opts? | RunCodeOpts & object | options for executing the code. |
Returns
Promise<Execution>
Execution result object.
runCode(code, opts)
language or context option to run the code as a different language or in a different Context.
If no language is specified, Python is used.
You can reference previously defined variables, imports, and functions in the code.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | string | code to execute. |
opts? | RunCodeOpts & object | options for executing the code. |
Returns
Promise<Execution>
Execution result object.
runCode(code, opts)
language or context option to run the code as a different language or in a different Context.
You can reference previously defined variables, imports, and functions in the code.
Parameters
| Parameter | Type | Description |
|---|---|---|
code | string | code to execute. |
opts? | RunCodeOpts & object | options for executing the code |
Returns
Promise<Execution>
Execution result object
Interfaces
CreateCodeContextOpts
Options for creating a code context.Properties
cwd?
Default
language?
Default
requestTimeoutMs?
Default
RunCodeOpts
Options for running code.Properties
envs?
Default
onError()?
ExecutionError object.
Parameters
| Parameter | Type |
|---|---|
error | ExecutionError |
Returns
any
onResult()?
Parameters
| Parameter | Type |
|---|---|
data | Result |
Returns
any
onStderr()?
Parameters
| Parameter | Type |
|---|---|
output | OutputMessage |
Returns
any
onStdout()?
Parameters
| Parameter | Type |
|---|---|
output | OutputMessage |
Returns
any
requestTimeoutMs?
Default
timeoutMs?
Default
Type Aliases
Context
Type declaration
| Name | Type | Description |
|---|---|---|
cwd | string | The working directory of the context. |
id | string | The ID of the context. |
language | string | The language of the context. |