Skip to main content

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
Check docs here. Use Sandbox.create to create a new sandbox.

Example

Methods

createCodeContext()

Creates a new context to run code in.
Parameters
Returns
Promise<Context> context object.

runCode()

runCode(code, opts)
Run the code as Python. Specify the 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
Returns
Promise<Execution> Execution result object.
runCode(code, opts)
Run the code for the specified language. Specify the 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
Returns
Promise<Execution> Execution result object.
runCode(code, opts)
Runs the code in the specified context, if not specified, the default context is used. Specify the 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
Returns
Promise<Execution> Execution result object

Interfaces

CreateCodeContextOpts

Options for creating a code context.

Properties

cwd?

Working directory for the context.
Default

language?

Language for the context.
Default

requestTimeoutMs?

Timeout for the request in milliseconds.
Default

RunCodeOpts

Options for running code.

Properties

envs?

Custom environment variables for code execution.
Default

onError()?

Callback for handling the ExecutionError object.
Parameters
Returns
any

onResult()?

Callback for handling the final execution result.
Parameters
Returns
any

onStderr()?

Callback for handling stderr messages.
Parameters
Returns
any

onStdout()?

Callback for handling stdout messages.
Parameters
Returns
any

requestTimeoutMs?

Timeout for the request in milliseconds.
Default

timeoutMs?

Timeout for the code execution in milliseconds.
Default

Type Aliases

Context

Represents a context for code execution.

Type declaration