e2b

package
v1.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package e2b provides a CodeExecutor implementation for E2B.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeExecutor

type CodeExecutor struct {
	// contains filtered or unexported fields
}

CodeExecutor executes code inside an E2B code-interpreter sandbox.

func New

func New(opts ...Option) (*CodeExecutor, error)

New creates a new CodeExecutor. When `WithSandboxID` is supplied it connects to an existing sandbox; otherwise a new sandbox is created.

func NewWithContext

func NewWithContext(ctx context.Context, opts ...Option) (*CodeExecutor, error)

NewWithContext is like New but accepts a context used for sandbox setup.

func (*CodeExecutor) Cleanup

func (c *CodeExecutor) Cleanup(
	ctx context.Context, ws codeexecutor.Workspace,
) error

Cleanup removes the workspace directory inside the sandbox.

func (*CodeExecutor) Close

func (c *CodeExecutor) Close() error

Close terminates the owned sandbox (if any).

func (*CodeExecutor) CodeBlockDelimiter

func (c *CodeExecutor) CodeBlockDelimiter() codeexecutor.CodeBlockDelimiter

CodeBlockDelimiter returns the fenced code delimiter.

func (*CodeExecutor) Collect

func (c *CodeExecutor) Collect(
	ctx context.Context, ws codeexecutor.Workspace, patterns []string,
) ([]codeexecutor.File, error)

Collect reads matching files from the sandbox workspace.

func (*CodeExecutor) CollectOutputs

CollectOutputs applies the declarative output spec in the sandbox.

func (*CodeExecutor) CreateWorkspace

func (c *CodeExecutor) CreateWorkspace(
	ctx context.Context, execID string, pol codeexecutor.WorkspacePolicy,
) (codeexecutor.Workspace, error)

CreateWorkspace creates a workspace inside the sandbox.

func (*CodeExecutor) Engine

func (c *CodeExecutor) Engine() codeexecutor.Engine

Engine exposes the sandbox-backed runtime as an Engine for skill tools.

func (*CodeExecutor) ExecuteCode

ExecuteCode executes all code blocks sequentially in the sandbox and aggregates their output.

func (*CodeExecutor) ExecuteInline

func (c *CodeExecutor) ExecuteInline(
	ctx context.Context, execID string,
	blocks []codeexecutor.CodeBlock, timeout time.Duration,
) (codeexecutor.RunResult, error)

ExecuteInline writes inline code blocks into the sandbox and runs them.

func (*CodeExecutor) PutDirectory

func (c *CodeExecutor) PutDirectory(
	ctx context.Context, ws codeexecutor.Workspace, hostPath, to string,
) error

PutDirectory copies a host directory into the sandbox workspace.

func (*CodeExecutor) PutFiles

func (c *CodeExecutor) PutFiles(
	ctx context.Context, ws codeexecutor.Workspace,
	files []codeexecutor.PutFile,
) error

PutFiles writes files into the sandbox workspace.

func (*CodeExecutor) RunProgram

RunProgram executes a command inside the sandbox workspace.

func (*CodeExecutor) Sandbox

func (c *CodeExecutor) Sandbox() *ci.Sandbox

Sandbox exposes the underlying sandbox for advanced usage.

func (*CodeExecutor) SandboxID

func (c *CodeExecutor) SandboxID() string

SandboxID returns the current sandbox id.

func (*CodeExecutor) StageDirectory

func (c *CodeExecutor) StageDirectory(
	ctx context.Context, ws codeexecutor.Workspace,
	src, to string, opt codeexecutor.StageOptions,
) error

StageDirectory stages a host directory with options into the sandbox.

func (*CodeExecutor) StageInputs

func (c *CodeExecutor) StageInputs(
	ctx context.Context, ws codeexecutor.Workspace,
	specs []codeexecutor.InputSpec,
) error

StageInputs maps external inputs into the sandbox workspace.

type Option

type Option func(*CodeExecutor)

Option configures a CodeExecutor.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the E2B API key. When empty the E2B_API_KEY env var is used.

func WithAccessToken

func WithAccessToken(token string) Option

WithAccessToken sets the envd access token.

func WithDebug

func WithDebug(debug bool) Option

WithDebug toggles debug mode (plain HTTP to local sandboxes).

func WithDomain

func WithDomain(domain string) Option

WithDomain overrides the E2B domain (default: e2b.app).

func WithEnvVars

func WithEnvVars(vars map[string]string) Option

WithEnvVars sets environment variables injected into the sandbox at start.

func WithExecutionTimeout

func WithExecutionTimeout(t time.Duration) Option

WithExecutionTimeout sets the per-cell code execution timeout. Use a negative value to disable timeouts.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient overrides the underlying HTTP client.

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders sets additional HTTP headers applied to every API call.

func WithLanguage

func WithLanguage(lang ci.RunCodeLanguage) Option

WithLanguage sets the default language used when a code block does not specify one (default: python).

func WithMetadata

func WithMetadata(meta map[string]string) Option

WithMetadata attaches metadata to the sandbox.

func WithRequestTimeout

func WithRequestTimeout(t time.Duration) Option

WithRequestTimeout sets the HTTP request timeout.

func WithSandboxID

func WithSandboxID(sandboxID string) Option

WithSandboxID connects to an existing sandbox instead of creating one.

func WithSandboxRunBase

func WithSandboxRunBase(dir string) Option

WithSandboxRunBase sets the base directory **inside the sandbox** where per-execution workspaces are created (default: /tmp/run).

func WithSandboxTimeout

func WithSandboxTimeout(t time.Duration) Option

WithSandboxTimeout sets the wall-clock lifetime of the sandbox.

func WithTemplate

func WithTemplate(template string) Option

WithTemplate sets the sandbox template (default: code-interpreter-v1).

Directories

Path Synopsis
internal
codeinterpreter
Package codeinterpreter provides a CodeInterpreter implementation for E2B.
Package codeinterpreter provides a CodeInterpreter implementation for E2B.
codeinterpreter/example command
Example command demonstrating typical use of the Go Code Interpreter SDK.
Example command demonstrating typical use of the Go Code Interpreter SDK.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL