building-columnsSandbox: E2B

E2B provides cloud-hosted, isolated sandboxes. Each sandbox is a fresh VM that persists across multiple execute_code calls within the same session.

Prerequisites

Setup

from gllm_tools.code_interpreter.code_sandbox.e2b_sandbox import E2BSandbox

sandbox = await E2BSandbox.create(
    api_key="your-e2b-api-key",
    additional_packages=["pandas", "matplotlib"],  # installed via pip on creation
)

Note: E2B uses an async factory method E2BSandbox.create(). Do not call E2BSandbox() directly.

Constructor Parameters

Parameter
Type
Default
Description

api_key

str

required

Your E2B API key

domain

str | None

None

Custom E2B domain (for self-hosted). Defaults to E2B SaaS.

template

str | None

None

E2B sandbox template name

language

str

"python"

Programming language (only Python supported)

additional_packages

list[str] | None

None

pip packages to install on initialization

Full Example

With SandboxCodeInterpreter

Notes

  • State persists across multiple execute_code calls within the same session (imports and variables are retained).

  • Files uploaded via files= parameter land at /files/<filename>.

  • Files downloaded via download_file(path) return raw bytes.

Last updated

Was this helpful?