e2b

package module
v0.0.0-...-b7fdfb2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 21 Imported by: 0

README

e2b-go

Go Reference Go Report Card

An unofficial Go SDK for E2B.

e2b-go gives Go applications access to the same core runtime workflows that exist in the JavaScript and Python SDKs: sandbox lifecycle management, filesystem operations, command execution, PTY sessions, snapshots, metrics, and persistent volumes.

Why This Exists

E2B ships official SDKs for JavaScript and Python, but there is no first-class Go SDK today. This project fills that gap with a Go-native client aimed at practical parity for backend and agent workloads.

This project is unofficial and is not affiliated with or endorsed by E2B. If an official Go SDK lands upstream, this repo should ideally become unnecessary.

Status

This project is in beta.

  • The core sandbox, process, PTY, and volume runtime surface is implemented.
  • go test ./... passes.
  • go test -race ./... passes.
  • Live integration coverage against a real E2B environment is still missing.

That means the SDK is in good shape for early adopters, but it should still be treated as a fast-moving package rather than a fully hardened, long-term-stable API.

Requirements

  • Go 1.25+
  • An E2B API key

Installation

go get github.com/Atharva-Kanherkar/e2b-go@latest

Quick Start

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/Atharva-Kanherkar/e2b-go"
)

func main() {
	ctx := context.Background()
	client := e2b.NewClient("E2B_API_KEY")

	sb, err := client.CreateSandbox(ctx, e2b.CreateRequest{
		TemplateID: "base",
		Timeout:    5 * time.Minute,
	})
	if err != nil {
		panic(err)
	}
	defer sb.Destroy(ctx)

	if err := sb.WriteFile(ctx, "/workspace/hello.txt", []byte("hi")); err != nil {
		panic(err)
	}

	result, err := sb.Exec(ctx, e2b.ExecRequest{
		Command: []string{"cat", "/workspace/hello.txt"},
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(result.Stdout) // hi
}

Feature Coverage

Sandbox lifecycle
  • Create and destroy sandboxes
  • Connect to existing sandboxes
  • Fetch sandbox info and metrics
  • Pause sandboxes
  • Update sandbox timeouts
  • Create and list snapshots
Filesystem
  • Read and write files
  • List files or full directory entries
  • Stat and existence checks
  • Create directories
  • Rename and remove paths
  • Watch directories for filesystem events
  • Optional shell fallback for older or inconsistent envd behavior
Commands and PTY
  • Run foreground commands with collected stdout and stderr
  • Start background commands and reconnect to running processes
  • Send stdin, close stdin, and kill running processes
  • Create PTY sessions, send PTY input, resize terminals, and reconnect
Volumes
  • Create, connect, list, inspect, and destroy persistent volumes
  • Read, write, stat, list, mkdir, update metadata, and remove volume paths

Package Overview

For full API documentation, see the package docs on pkg.go.dev.

The public surface is organized around three main handles:

  • Client for control-plane operations such as sandbox and volume lifecycle
  • Sandbox for envd-backed filesystem, command, PTY, and runtime methods
  • Volume for persistent volume content operations

Error Handling

The package exposes sentinel errors intended for errors.Is checks:

  • e2b.ErrSandboxNotFound
  • e2b.ErrFileNotFound
  • e2b.ErrSandboxDestroyed
  • e2b.ErrVolumeNotFound

CreateRequest

CreateRequest controls sandbox provisioning:

Field Purpose
TemplateID Template to clone from. Required.
Timeout Sandbox lifetime cap. Zero uses the server default.
Metadata Metadata attached to the sandbox on create.
EnvVars Environment variables injected into sandbox processes.
AllowInternetAccess Enables unrestricted internet egress when true.
NetworkAllowlist Egress allowlist used when internet access is otherwise disabled.
AdditionalPackages Debian packages installed with apt-get before CreateSandbox returns.
AllowShellFallback Enables shell-based fallbacks for selected filesystem operations.

Architecture

The SDK uses three underlying transports:

  • Control plane REST API for sandbox lifecycle, metadata, snapshots, and team volumes
  • Envd ConnectRPC for sandbox filesystem, command, and PTY operations
  • Volume content REST API for persistent volume file operations using a bearer token

Testing

The current test suite is unit-test heavy and focuses on:

  • control-plane request and response normalization
  • envd ConnectRPC request shapes and stream handling
  • concurrency-sensitive command and watch flows
  • bearer-auth volume content operations

Run the checks locally with:

go test ./...
go test -race ./...

Roadmap

The highest-value remaining gaps are:

  • live integration tests against a real E2B environment
  • signed upload and download URL helpers
  • higher-level Git convenience APIs that exist in other SDKs

Contributing

Issues and pull requests are welcome.

If you want to extend surface area or align behavior with upstream SDKs, opening an issue first is helpful so the API shape can stay coherent.

Relationship To Upstream

This repository exists because there is no official Go SDK at the time of writing. If the E2B team decides to ship or adopt one upstream, aligning this project with that effort would be the best long-term outcome.

License

MIT. See LICENSE.

Documentation

Overview

Package e2b is an unofficial Go SDK for E2B sandboxes (https://e2b.dev).

A Client authenticates against the E2B control plane and creates Sandboxes. Each Sandbox exposes file and process operations backed by envd (the agent that runs inside every E2B microVM), over ConnectRPC.

Example

c := e2b.NewClient("E2B_API_KEY")
sb, err := c.CreateSandbox(ctx, e2b.CreateRequest{
    TemplateID: "base",
    Timeout:    5 * time.Minute,
})
if err != nil {
    return err
}
defer sb.Destroy(ctx)

_, err = sb.WriteFile(ctx, "/workspace/hello.txt", []byte("hi"))
if err != nil {
    return err
}

result, err := sb.Exec(ctx, e2b.ExecRequest{
    Command: []string{"cat", "/workspace/hello.txt"},
})
// result.Stdout == "hi"

This SDK is not affiliated with or endorsed by E2B. See https://github.com/e2b-dev/E2B/issues/985 for upstream status.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSandboxNotFound indicates the sandbox ID is unknown to the control
	// plane — typically because it has already been destroyed or timed out.
	ErrSandboxNotFound = errors.New("e2b: sandbox not found")

	// ErrFileNotFound is returned by file operations when the target path
	// does not exist in the sandbox.
	ErrFileNotFound = errors.New("e2b: file not found")

	// ErrSandboxDestroyed is returned by any operation on a Sandbox whose
	// Destroy has already been called.
	ErrSandboxDestroyed = errors.New("e2b: sandbox is destroyed")

	// ErrVolumeNotFound indicates the volume ID is unknown to the control
	// plane.
	ErrVolumeNotFound = errors.New("e2b: volume not found")
)

Sentinel errors returned by this package. Callers should branch on them with errors.Is.

Functions

This section is empty.

Types

type Client

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

Client is an authenticated handle to the E2B control plane. Safe for concurrent use.

func NewClient

func NewClient(apiKey string) *Client

NewClient constructs a Client with just an API key. For more control (custom timeout, staging host), use NewClientWithConfig.

func NewClientWithConfig

func NewClientWithConfig(config Config) *Client

NewClientWithConfig constructs a Client from a fully-specified Config.

func (*Client) ConnectSandbox

func (c *Client) ConnectSandbox(ctx context.Context, request ConnectSandboxRequest) (*Sandbox, error)

func (*Client) ConnectVolume

func (c *Client) ConnectVolume(ctx context.Context, volumeID string) (*Volume, error)

ConnectVolume loads an existing volume and returns a handle to its content API.

func (*Client) CreateSandbox

func (c *Client) CreateSandbox(ctx context.Context, request CreateRequest) (*Sandbox, error)

CreateSandbox provisions a new sandbox from the given template and returns a handle for interacting with it. Callers are responsible for calling Destroy to release the sandbox.

AdditionalPackages, when non-empty, are installed via apt-get inside the sandbox before the call returns. Install failures cause the sandbox to be destroyed and the error propagated.

func (*Client) CreateVolume

func (c *Client) CreateVolume(ctx context.Context, name string) (*Volume, error)

CreateVolume creates a new persistent volume.

func (*Client) DeleteSnapshot

func (c *Client) DeleteSnapshot(ctx context.Context, snapshotID string) (bool, error)

func (*Client) DestroyVolume

func (c *Client) DestroyVolume(ctx context.Context, volumeID string) (bool, error)

DestroyVolume deletes a volume. It returns false when the volume is already gone.

func (*Client) EnvdURL

func (c *Client) EnvdURL(sandboxID string) string

EnvdURL returns the envd base URL for a given sandbox ID. Useful for debugging or direct gRPC-Web inspection. The sandbox must exist; otherwise the URL will 404.

func (*Client) GetSandboxInfo

func (c *Client) GetSandboxInfo(ctx context.Context, sandboxID string) (SandboxInfo, error)

func (*Client) GetVolumeInfo

func (c *Client) GetVolumeInfo(ctx context.Context, volumeID string) (VolumeAndToken, error)

GetVolumeInfo loads a volume and its content token.

func (*Client) ListSandboxes

func (c *Client) ListSandboxes(ctx context.Context, request ListSandboxesRequest) (ListSandboxesResponse, error)

func (*Client) ListSnapshots

func (c *Client) ListSnapshots(ctx context.Context, request ListSnapshotsRequest) (ListSnapshotsResponse, error)

func (*Client) ListVolumes

func (c *Client) ListVolumes(ctx context.Context) ([]VolumeInfo, error)

ListVolumes returns all team volumes.

type CommandConnectOptions

type CommandConnectOptions struct {
	OnStdout func(string)
	OnStderr func(string)
}

CommandConnectOptions controls command stream callbacks.

type CommandHandle

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

CommandHandle tracks a running command or PTY session.

func (*CommandHandle) CloseStdin

func (h *CommandHandle) CloseStdin(ctx context.Context) error

CloseStdin closes stdin, signaling EOF to the process.

func (*CommandHandle) Disconnect

func (h *CommandHandle) Disconnect()

Disconnect stops receiving stream events without killing the process.

func (*CommandHandle) Kill

func (h *CommandHandle) Kill(ctx context.Context) (bool, error)

Kill sends SIGKILL to the process.

func (*CommandHandle) PID

func (h *CommandHandle) PID() uint32

PID returns the process ID.

func (*CommandHandle) PTYOutput

func (h *CommandHandle) PTYOutput() []byte

PTYOutput returns the PTY bytes captured so far.

func (*CommandHandle) ResizePTY

func (h *CommandHandle) ResizePTY(ctx context.Context, cols uint32, rows uint32) error

ResizePTY resizes a PTY session.

func (*CommandHandle) SendPTY

func (h *CommandHandle) SendPTY(ctx context.Context, data []byte) error

SendPTY writes bytes to a PTY session.

func (*CommandHandle) SendStdin

func (h *CommandHandle) SendStdin(ctx context.Context, data []byte) error

SendStdin writes to a command's stdin stream.

func (*CommandHandle) Stderr

func (h *CommandHandle) Stderr() string

Stderr returns the stderr captured so far.

func (*CommandHandle) Stdout

func (h *CommandHandle) Stdout() string

Stdout returns the stdout captured so far.

func (*CommandHandle) Wait

func (h *CommandHandle) Wait() (CommandResult, error)

Wait blocks until the process stream ends and returns the final result.

type CommandResult

type CommandResult struct {
	ExitCode  int
	Stdout    string
	Stderr    string
	PTYOutput []byte
	Metadata  map[string]string
}

CommandResult is returned by CommandHandle.Wait.

type CommandStartRequest

type CommandStartRequest struct {
	Command          []string
	WorkingDirectory string
	Environment      map[string]string
	Tag              string
	Stdin            bool
	OnStdout         func(string)
	OnStderr         func(string)
}

CommandStartRequest starts a background command.

type Config

type Config struct {
	// APIKey authenticates all control-plane calls. Required.
	APIKey string
	// APIBaseURL overrides the control-plane host. Defaults to
	// https://api.e2b.app when empty.
	APIBaseURL string
	// RequestTimeout bounds every HTTP call to the control plane.
	// Defaults to 30s when zero.
	RequestTimeout time.Duration
}

Config carries connection settings for a Client. Zero values fall back to sensible defaults (production API, 30s HTTP timeout).

type ConnectSandboxRequest

type ConnectSandboxRequest struct {
	SandboxID          string
	Timeout            time.Duration
	AllowShellFallback bool
}

ConnectSandboxRequest reconnects to an existing sandbox, resuming it if needed.

type CreateRequest

type CreateRequest struct {
	// TemplateID is the E2B template the sandbox is cloned from. Required.
	TemplateID string

	// Timeout bounds the lifetime of the sandbox. If zero, the E2B server's
	// default applies.
	Timeout time.Duration

	// Metadata is attached to the sandbox on creation and is visible on
	// the control plane. Commonly used for user / project / trace IDs.
	Metadata map[string]string

	// EnvVars are injected into every process started in the sandbox.
	EnvVars map[string]string

	// AllowInternetAccess controls whether the sandbox can reach the public
	// internet. Default is false (network-isolated).
	AllowInternetAccess bool

	// NetworkAllowlist is an egress allowlist of CIDRs / hostnames. Only
	// honored when AllowInternetAccess is false — the listed destinations
	// remain reachable.
	NetworkAllowlist []string

	// AdditionalPackages are installed via apt-get at sandbox start. Useful
	// for one-off extensions of a base template without rebuilding it.
	AdditionalPackages []string

	// AllowShellFallback enables shell-based fallbacks (cat, find) when
	// envd ConnectRPC calls fail. Useful for older envd versions or envd
	// bugs; default false.
	AllowShellFallback bool
}

CreateRequest configures a new sandbox. TemplateID is required; all other fields are optional.

type CreateSnapshotRequest

type CreateSnapshotRequest struct {
	Name string
}

CreateSnapshotRequest controls snapshot creation.

type EntryInfo

type EntryInfo struct {
	Name          string
	Type          FilesystemEntryType
	Path          string
	Size          int64
	Mode          uint32
	Permissions   string
	Owner         string
	Group         string
	ModifiedTime  time.Time
	SymlinkTarget string
}

EntryInfo describes a filesystem object inside the sandbox.

type ExecRequest

type ExecRequest struct {
	// Command is an argv slice. Command[0] is the executable; the rest are
	// positional arguments.
	Command []string

	// WorkingDirectory sets the cwd. Empty means the sandbox default.
	WorkingDirectory string

	// Environment merges with the sandbox-level EnvVars for this call.
	Environment map[string]string

	// Timeout bounds the call. Zero means no deadline beyond the parent ctx.
	Timeout time.Duration
}

ExecRequest describes a command to run inside a sandbox.

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	// Metadata carries envd-provided diagnostics (e.g. an "error" key when
	// the process itself reported a launch failure).
	Metadata map[string]string
}

ExecResult is returned by Sandbox.Exec after the process has finished.

type FileInfo

type FileInfo struct {
	Path string
	Size int64
}

FileInfo describes a file returned by Sandbox.ListFiles.

type FilesystemEntryType

type FilesystemEntryType string

FilesystemEntryType describes the kind of object returned by filesystem RPCs.

const (
	FilesystemEntryTypeUnknown   FilesystemEntryType = "unknown"
	FilesystemEntryTypeFile      FilesystemEntryType = "file"
	FilesystemEntryTypeDirectory FilesystemEntryType = "directory"
	FilesystemEntryTypeSymlink   FilesystemEntryType = "symlink"
)

type FilesystemEvent

type FilesystemEvent struct {
	Name string
	Type FilesystemEventType
}

FilesystemEvent is delivered to directory watch callbacks.

type FilesystemEventType

type FilesystemEventType string

FilesystemEventType is emitted by directory watches.

const (
	FilesystemEventTypeCreate FilesystemEventType = "create"
	FilesystemEventTypeWrite  FilesystemEventType = "write"
	FilesystemEventTypeRemove FilesystemEventType = "remove"
	FilesystemEventTypeRename FilesystemEventType = "rename"
	FilesystemEventTypeChmod  FilesystemEventType = "chmod"
)

type ListSandboxesRequest

type ListSandboxesRequest struct {
	Metadata  map[string]string
	States    []SandboxState
	Limit     int
	NextToken string
}

ListSandboxesRequest filters and paginates sandbox listing.

type ListSandboxesResponse

type ListSandboxesResponse struct {
	Sandboxes []SandboxInfo
	NextToken string
}

ListSandboxesResponse contains one page of sandboxes and the next token.

type ListSnapshotsRequest

type ListSnapshotsRequest struct {
	SandboxID string
	Limit     int
	NextToken string
}

ListSnapshotsRequest filters and paginates snapshot listing.

type ListSnapshotsResponse

type ListSnapshotsResponse struct {
	Snapshots []SnapshotInfo
	NextToken string
}

ListSnapshotsResponse contains one page of snapshots and the next token.

type PTYConnectOptions

type PTYConnectOptions struct {
	OnData func([]byte)
}

PTYConnectOptions controls PTY stream callbacks.

type PTYStartRequest

type PTYStartRequest struct {
	Cols             uint32
	Rows             uint32
	WorkingDirectory string
	Environment      map[string]string
	Tag              string
	OnData           func([]byte)
}

PTYStartRequest starts a shell-backed PTY session.

type ProcessInfo

type ProcessInfo struct {
	PID              uint32
	Tag              string
	Command          string
	Args             []string
	Environment      map[string]string
	WorkingDirectory string
}

ProcessInfo describes a running command or PTY session.

type Sandbox

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

Sandbox is a handle to a live E2B microVM. Methods are safe for concurrent use.

func (*Sandbox) CloseStdin

func (s *Sandbox) CloseStdin(ctx context.Context, pid uint32) error

CloseStdin closes stdin for a running process.

func (*Sandbox) Connect

func (s *Sandbox) Connect(ctx context.Context, timeout time.Duration) error

func (*Sandbox) ConnectPTY

func (s *Sandbox) ConnectPTY(ctx context.Context, pid uint32, options PTYConnectOptions) (*CommandHandle, error)

ConnectPTY reconnects to a running PTY session by PID.

func (*Sandbox) ConnectProcess

func (s *Sandbox) ConnectProcess(ctx context.Context, pid uint32, options CommandConnectOptions) (*CommandHandle, error)

ConnectProcess reconnects to a running command stream by PID.

func (*Sandbox) CreatePTY

func (s *Sandbox) CreatePTY(ctx context.Context, request PTYStartRequest) (*CommandHandle, error)

CreatePTY starts a shell-backed PTY session and returns a handle.

func (*Sandbox) CreateSnapshot

func (s *Sandbox) CreateSnapshot(ctx context.Context, request CreateSnapshotRequest) (SnapshotInfo, error)

func (*Sandbox) Destroy

func (s *Sandbox) Destroy(ctx context.Context) error

Destroy terminates the sandbox. Safe to call more than once; only the first call hits the control plane. Returns nil when the sandbox was already gone.

func (*Sandbox) EnvdURL

func (s *Sandbox) EnvdURL() string

EnvdURL returns the envd base URL for this sandbox.

func (*Sandbox) Exec

func (s *Sandbox) Exec(ctx context.Context, request ExecRequest) (ExecResult, error)

Exec runs a command in the sandbox, collecting stdout and stderr, and returns once the process exits or the context is cancelled.

func (*Sandbox) Exists

func (s *Sandbox) Exists(ctx context.Context, path string) (bool, error)

Exists returns true when a file or directory exists.

func (*Sandbox) GetHost

func (s *Sandbox) GetHost(port int) string

func (*Sandbox) GetInfo

func (s *Sandbox) GetInfo(ctx context.Context) (SandboxInfo, error)

func (*Sandbox) GetMetrics

func (s *Sandbox) GetMetrics(ctx context.Context, request SandboxMetricsRequest) ([]SandboxMetric, error)

func (*Sandbox) ID

func (s *Sandbox) ID() string

ID returns the E2B sandbox identifier.

func (*Sandbox) Kill

func (s *Sandbox) Kill(ctx context.Context) error

Kill is an alias for Destroy to match the control-plane naming used in the upstream SDKs.

func (*Sandbox) KillPTY

func (s *Sandbox) KillPTY(ctx context.Context, pid uint32) (bool, error)

KillPTY sends SIGKILL to a PTY session.

func (*Sandbox) KillProcess

func (s *Sandbox) KillProcess(ctx context.Context, pid uint32) (bool, error)

KillProcess sends SIGKILL to a running process.

func (*Sandbox) ListDir

func (s *Sandbox) ListDir(ctx context.Context, path string, depth uint32) ([]EntryInfo, error)

ListDir lists files, directories, and symlinks under the given path. Depth defaults to 1 when zero.

func (*Sandbox) ListFiles

func (s *Sandbox) ListFiles(ctx context.Context, prefix string) ([]FileInfo, error)

ListFiles enumerates files beneath the given prefix, up to 32 levels deep. Directories are skipped. When AllowShellFallback is set and the envd RPC fails, a `find` backstop is used.

func (*Sandbox) ListProcesses

func (s *Sandbox) ListProcesses(ctx context.Context) ([]ProcessInfo, error)

ListProcesses lists running commands and PTY sessions.

func (*Sandbox) ListSnapshots

func (s *Sandbox) ListSnapshots(ctx context.Context, request ListSnapshotsRequest) (ListSnapshotsResponse, error)

func (*Sandbox) MakeDir

func (s *Sandbox) MakeDir(ctx context.Context, path string) (bool, error)

MakeDir creates a directory. It returns false when the directory already exists.

func (*Sandbox) Pause

func (s *Sandbox) Pause(ctx context.Context) (bool, error)

func (*Sandbox) ReadFile

func (s *Sandbox) ReadFile(ctx context.Context, path string) ([]byte, error)

ReadFile returns the contents of a file inside the sandbox. When AllowShellFallback is set and the envd HTTP call fails, a shell-based `cat` is tried as a backstop.

func (*Sandbox) Remove

func (s *Sandbox) Remove(ctx context.Context, path string) error

Remove deletes a file or directory.

func (*Sandbox) Rename

func (s *Sandbox) Rename(ctx context.Context, oldPath string, newPath string) (EntryInfo, error)

Rename renames or moves a filesystem entry.

func (*Sandbox) ResizePTY

func (s *Sandbox) ResizePTY(ctx context.Context, pid uint32, cols uint32, rows uint32) error

ResizePTY resizes a running PTY session.

func (*Sandbox) SendPTYInput

func (s *Sandbox) SendPTYInput(ctx context.Context, pid uint32, data []byte) error

SendPTYInput writes bytes to a running PTY session.

func (*Sandbox) SendStdin

func (s *Sandbox) SendStdin(ctx context.Context, pid uint32, data []byte) error

SendStdin writes to the stdin of a running process.

func (*Sandbox) SetTimeout

func (s *Sandbox) SetTimeout(ctx context.Context, timeout time.Duration) error

func (*Sandbox) StartCommand

func (s *Sandbox) StartCommand(ctx context.Context, request CommandStartRequest) (*CommandHandle, error)

StartCommand starts a background command and returns a handle.

func (*Sandbox) Stat

func (s *Sandbox) Stat(ctx context.Context, path string) (EntryInfo, error)

Stat returns metadata about a single sandbox filesystem entry.

func (*Sandbox) TemplateID

func (s *Sandbox) TemplateID() string

TemplateID returns the template the sandbox was cloned from.

func (*Sandbox) WatchDir

func (s *Sandbox) WatchDir(ctx context.Context, path string, options WatchOptions, onEvent func(FilesystemEvent)) (*WatchHandle, error)

WatchDir starts watching a directory for filesystem events.

func (*Sandbox) WriteFile

func (s *Sandbox) WriteFile(ctx context.Context, path string, content []byte) error

WriteFile writes content to the given path inside the sandbox, creating parent directories as needed.

type SandboxInfo

type SandboxInfo struct {
	SandboxID           string
	TemplateID          string
	Name                string
	Metadata            map[string]string
	StartedAt           time.Time
	EndAt               time.Time
	State               SandboxState
	CPUCount            int
	MemoryMB            int
	DiskSizeMB          int
	EnvdVersion         string
	AllowInternetAccess *bool
	Domain              string
	Network             *SandboxNetwork
	Lifecycle           *SandboxLifecycle
	VolumeMounts        []SandboxVolumeMount
}

SandboxInfo is returned by sandbox list/info APIs.

type SandboxLifecycle

type SandboxLifecycle struct {
	AutoResume bool
	OnTimeout  string
}

SandboxLifecycle describes timeout and auto-resume behavior.

type SandboxMetric

type SandboxMetric struct {
	Timestamp     time.Time
	TimestampUnix int64
	CPUCount      int
	CPUUsedPct    float64
	MemUsed       int64
	MemTotal      int64
	DiskUsed      int64
	DiskTotal     int64
}

SandboxMetric is a single resource-usage sample from the control plane.

type SandboxMetricsRequest

type SandboxMetricsRequest struct {
	Start time.Time
	End   time.Time
}

SandboxMetricsRequest constrains the requested metric interval.

type SandboxNetwork

type SandboxNetwork struct {
	AllowPublicTraffic *bool
	AllowOut           []string
	DenyOut            []string
	MaskRequestHost    string
}

SandboxNetwork describes control-plane network configuration.

type SandboxState

type SandboxState string

SandboxState is the control-plane lifecycle state of a sandbox.

const (
	// SandboxStateRunning indicates the sandbox is running.
	SandboxStateRunning SandboxState = "running"
	// SandboxStatePaused indicates the sandbox is paused.
	SandboxStatePaused SandboxState = "paused"
)

type SandboxVolumeMount

type SandboxVolumeMount struct {
	Name string
	Path string
}

SandboxVolumeMount describes a volume mounted into a sandbox.

type SnapshotInfo

type SnapshotInfo struct {
	SnapshotID string
	Names      []string
}

SnapshotInfo describes a persistent sandbox snapshot.

type Volume

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

Volume is a handle to a persistent E2B volume.

func (*Volume) Destroy

func (v *Volume) Destroy(ctx context.Context) (bool, error)

Destroy deletes the volume represented by this handle.

func (*Volume) Exists

func (v *Volume) Exists(ctx context.Context, path string) (bool, error)

Exists reports whether a path exists in the volume.

func (*Volume) ID

func (v *Volume) ID() string

ID returns the volume ID.

func (*Volume) List

func (v *Volume) List(ctx context.Context, path string, depth uint32) ([]VolumeEntryInfo, error)

List returns directory contents from the volume.

func (*Volume) MakeDir

func (v *Volume) MakeDir(ctx context.Context, path string, options VolumeWriteOptions) (VolumeEntryInfo, error)

MakeDir creates a directory in the volume.

func (*Volume) Name

func (v *Volume) Name() string

Name returns the volume name.

func (*Volume) ReadFile

func (v *Volume) ReadFile(ctx context.Context, path string) ([]byte, error)

ReadFile reads a file from the volume.

func (*Volume) Remove

func (v *Volume) Remove(ctx context.Context, path string) error

Remove deletes a file or directory from the volume.

func (*Volume) Stat

func (v *Volume) Stat(ctx context.Context, path string) (VolumeEntryInfo, error)

Stat returns metadata about a path in the volume.

func (*Volume) UpdateMetadata

func (v *Volume) UpdateMetadata(ctx context.Context, path string, options VolumeMetadataOptions) (VolumeEntryInfo, error)

UpdateMetadata updates uid/gid/mode for a volume path.

func (*Volume) WriteFile

func (v *Volume) WriteFile(ctx context.Context, path string, content []byte, options VolumeWriteOptions) (VolumeEntryInfo, error)

WriteFile writes a file to the volume.

type VolumeAndToken

type VolumeAndToken struct {
	VolumeID string
	Name     string
	Token    string
}

VolumeAndToken describes a persistent volume plus its content API token.

type VolumeEntryInfo

type VolumeEntryInfo struct {
	Name         string
	Type         VolumeEntryType
	Path         string
	Size         int64
	Mode         uint32
	UID          uint32
	GID          uint32
	AccessTime   time.Time
	ModifiedTime time.Time
	ChangeTime   time.Time
	Target       string
}

VolumeEntryInfo describes a file or directory in a volume.

type VolumeEntryType

type VolumeEntryType string

VolumeEntryType describes the type of a volume filesystem entry.

const (
	VolumeEntryTypeUnknown   VolumeEntryType = "unknown"
	VolumeEntryTypeFile      VolumeEntryType = "file"
	VolumeEntryTypeDirectory VolumeEntryType = "directory"
	VolumeEntryTypeSymlink   VolumeEntryType = "symlink"
)

type VolumeInfo

type VolumeInfo struct {
	VolumeID string
	Name     string
}

VolumeInfo describes a persistent volume.

type VolumeMetadataOptions

type VolumeMetadataOptions struct {
	UID  *uint32
	GID  *uint32
	Mode *uint32
}

VolumeMetadataOptions updates ownership or mode.

type VolumeWriteOptions

type VolumeWriteOptions struct {
	UID   *uint32
	GID   *uint32
	Mode  *uint32
	Force bool
}

VolumeWriteOptions controls file and directory creation.

type WatchHandle

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

WatchHandle controls a running directory watch.

func (*WatchHandle) Stop

func (h *WatchHandle) Stop()

Stop stops the watch.

func (*WatchHandle) Wait

func (h *WatchHandle) Wait() error

Wait blocks until the watch exits. A normal Stop returns nil.

type WatchOptions

type WatchOptions struct {
	Recursive bool
}

WatchOptions configures sandbox directory watches.

Jump to

Keyboard shortcuts

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