Skip to main content

OutputMessage

Represents an output message from the sandbox code execution.

line

The output line.

timestamp

Unix epoch in nanoseconds

error

Whether the output is an error.

ExecutionError

Represents an error that occurred during the execution of a cell. The error contains the name of the error, the value of the error, and the traceback.

name

Name of the error.

value

Value of the error.

traceback

The raw traceback of the error.

to_json

Returns the JSON representation of the Error object.

MIMEType

Represents a MIME type.

Result

Represents the data to be displayed as a result of executing a cell in a Jupyter notebook. The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented as a string, and the result can contain multiple types of data. The display calls don’t have to have text representation, for the actual result the representation is always present for the result, the other representations are always optional.

is_main_result

Whether this data is the result of the cell. Data can be produced by display calls of which can be multiple in a cell.

extra

Extra data that can be included. Not part of the standard types.

formats

Returns all available formats of the result. Returns: All available formats of the result in MIME types.

__str__

Returns the text representation of the data. Returns: The text representation of the data.

_repr_html_

Returns the HTML representation of the data. Returns: The HTML representation of the data.

_repr_markdown_

Returns the Markdown representation of the data. Returns: The Markdown representation of the data.

_repr_svg_

Returns the SVG representation of the data. Returns: The SVG representation of the data.

_repr_png_

Returns the base64 representation of the PNG data. Returns: The base64 representation of the PNG data.

_repr_jpeg_

Returns the base64 representation of the JPEG data. Returns: The base64 representation of the JPEG data.

_repr_pdf_

Returns the PDF representation of the data. Returns: The PDF representation of the data.

_repr_latex_

Returns the LaTeX representation of the data. Returns: The LaTeX representation of the data.

_repr_json_

Returns the JSON representation of the data. Returns: The JSON representation of the data.

_repr_javascript_

Returns the JavaScript representation of the data. Returns: The JavaScript representation of the data.

Logs

Data printed to stdout and stderr during execution, usually by print statements, logs, warnings, subprocesses, etc.

stdout

List of strings printed to stdout by prints, subprocesses, etc.

stderr

List of strings printed to stderr by prints, subprocesses, etc.

to_json

Returns the JSON representation of the Logs object.

serialize_results

Serializes the results to JSON.

Execution

Represents the result of a cell execution.

results

List of the result of the cell (interactively interpreted last line), display calls (e.g. matplotlib plots).

logs

Logs printed to stdout and stderr during execution.

error

Error object if an error occurred, None otherwise.

execution_count

Execution count of the cell.

text

Returns the text representation of the result. Returns: The text representation of the result.

to_json

Returns the JSON representation of the Execution object.

Context

Represents a context for code execution.

id

The ID of the context.

language

The language of the context.

cwd

The working directory of the context.

AsyncSandbox

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 the AsyncSandbox.create() to create a new sandbox. Example:

run_code

Runs 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. Arguments:
  • code: Code to execute
  • language: Language to use for code execution. If not defined, the default Python context is used.
  • on_stdout: Callback for stdout messages
  • on_stderr: Callback for stderr messages
  • on_result: Callback for the Result object
  • on_error: Callback for the ExecutionError object
  • envs: Custom environment variables
  • timeout: Timeout for the code execution in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Execution result object

run_code

Runs 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. Arguments:
  • code: Code to execute
  • language: Language to use for code execution. If not defined, the default Python context is used.
  • on_stdout: Callback for stdout messages
  • on_stderr: Callback for stderr messages
  • on_result: Callback for the Result object
  • on_error: Callback for the ExecutionError object
  • envs: Custom environment variables
  • timeout: Timeout for the code execution in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Execution result object

run_code

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. Arguments:
  • code: Code to execute
  • context: Concrete context to run the code in. If not specified, the default context for the language is used. It’s mutually exclusive with the language.
  • on_stdout: Callback for stdout messages
  • on_stderr: Callback for stderr messages
  • on_result: Callback for the Result object
  • on_error: Callback for the ExecutionError object
  • envs: Custom environment variables
  • timeout: Timeout for the code execution in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Execution result object

create_code_context

Creates a new context to run code in. Arguments:
  • cwd: Set the current working directory for the context, defaults to /home/user
  • language: Language of the context. If not specified, defaults to Python
  • request_timeout: Timeout for the request in milliseconds
Returns: Context object

ChartType

Chart types

ScaleType

Ax scale types

Chart

Extracted data from a chart. It’s useful for building an interactive charts or custom visualizations.

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 the Sandbox() to create a new sandbox. Example:

run_code

Runs 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. Arguments:
  • code: Code to execute
  • language: Language to use for code execution. If not defined, the default Python context is used.
  • on_stdout: Callback for stdout messages
  • on_stderr: Callback for stderr messages
  • on_result: Callback for the Result object
  • on_error: Callback for the ExecutionError object
  • envs: Custom environment variables
  • timeout: Timeout for the code execution in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Execution result object

run_code

Runs 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. Arguments:
  • code: Code to execute
  • language: Language to use for code execution. If not defined, the default Python context is used.
  • on_stdout: Callback for stdout messages
  • on_stderr: Callback for stderr messages
  • on_result: Callback for the Result object
  • on_error: Callback for the ExecutionError object
  • envs: Custom environment variables
  • timeout: Timeout for the code execution in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Execution result object

run_code

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. Arguments:
  • code: Code to execute
  • context: Concrete context to run the code in. If not specified, the default context for the language is used. It’s mutually exclusive with the language.
  • on_stdout: Callback for stdout messages
  • on_stderr: Callback for stderr messages
  • on_result: Callback for the Result object
  • on_error: Callback for the ExecutionError object
  • envs: Custom environment variables
  • timeout: Timeout for the code execution in seconds
  • request_timeout: Timeout for the request in seconds
Returns: Execution result object

create_code_context

Creates a new context to run code in. Arguments:
  • cwd: Set the current working directory for the context, defaults to /home/user
  • language: Language of the context. If not specified, defaults to Python
  • request_timeout: Timeout for the request in milliseconds
Returns: Context object