volume

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package volume provides a client for E2B persistent volumes.

A Volume is independent of a specific sandbox: it can be mounted via e2b.VolumeMount during Sandbox.Create / CreateV1. Control-plane operations (/volumes) manage volume lifecycles and mint per-volume JWTs, while content operations (/volumecontent/{volumeID}/*) read, stream, write, list, and mutate files and directories inside the volume.

Index

Constants

View Source
const DefaultFileTransferTimeout = time.Hour

DefaultFileTransferTimeout bounds single volume file downloads and uploads when the caller's context carries no deadline (1 hour, matching the official JavaScript and Python SDKs).

Variables

This section is empty.

Functions

func Destroy added in v0.1.4

func Destroy(ctx context.Context, volumeID string, opts Options) (bool, error)

Destroy deletes volumeID permanently using a one-shot Client built from opts.Config, returning (false, nil) on HTTP 404.

Endpoint: DELETE /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

Types

type Client added in v0.1.4

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

Client manages persistent volumes on the E2B control plane and constructs Volume handles backed by shared pooled HTTP clients.

Control-plane calls (/volumes) use ControlPlaneHTTPClient (retries + RequestTimeout), while volume-content calls (/volumecontent/{id}/*) use DataPlaneHTTPClient (no client-wide timeout cutoff and no control-plane retry wrapper on streaming uploads/downloads).

A *Client is safe for concurrent use.

func NewClient added in v0.1.4

func NewClient(cfg e2b.Config) (*Client, error)

NewClient resolves cfg (applying E2B_* environment-variable fallbacks and defaults) and constructs a shared volume Client. It returns *e2b.InvalidArgumentError if cfg specifies an invalid Proxy or HTTPVersion.

func (*Client) Config added in v0.1.4

func (c *Client) Config() e2b.Config

Config returns a deep copy of the resolved e2b.Config backing this Client.

func (*Client) Connect added in v0.1.4

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

Connect looks up an existing volume by ID, mints a fresh per-volume JWT and optional BYOC domain from the control plane, and returns a Volume handle.

Endpoint: GET /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Client) ConnectWithToken added in v0.1.4

func (c *Client) ConnectWithToken(volumeID, token string, domain ...string) (*Volume, error)

ConnectWithToken constructs a Volume handle locally from a pre-minted JWT without making a control-plane HTTP round-trip. An optional BYOC domain overrides Config.Domain when routing volume-content requests.

func (*Client) Create added in v0.1.4

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

Create provisions a new persistent volume and returns a tokenized Volume handle. When the server returns a BYOC cluster domain, content traffic is routed to https://api.<domain>; when domain is absent (non-BYOC E2B Cloud and self-hosted runtimes), it falls back to the resolved Config.Domain.

Endpoint: POST /volumes Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Client) Destroy added in v0.1.4

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

Destroy permanently deletes volumeID. It returns (false, nil) when the volume does not exist (HTTP 404).

Endpoint: DELETE /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Client) GetInfo added in v0.1.4

func (c *Client) GetInfo(ctx context.Context, volumeID string) (*Info, error)

GetInfo retrieves volume metadata, a freshly minted content JWT, and the optional BYOC cluster domain for volumeID.

Endpoint: GET /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Client) List added in v0.1.4

func (c *Client) List(ctx context.Context) ([]Info, error)

List returns all persistent volumes visible to the authenticated team.

Endpoint: GET /volumes Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

type EntryStat added in v0.1.4

type EntryStat struct {
	Name   string    `json:"name"`
	Type   EntryType `json:"type"`
	Path   string    `json:"path"`
	Size   int64     `json:"size"`
	Mode   uint32    `json:"mode"`
	UID    uint32    `json:"uid"`
	GID    uint32    `json:"gid"`
	ATime  time.Time `json:"atime"`
	MTime  time.Time `json:"mtime"`
	CTime  time.Time `json:"ctime"`
	Target string    `json:"target,omitempty"`
}

EntryStat describes a file, directory, or symlink inside a persistent volume.

type EntryType added in v0.1.4

type EntryType string

EntryType classifies a filesystem entry inside a persistent volume.

const (
	EntryTypeUnknown   EntryType = "unknown"
	EntryTypeFile      EntryType = "file"
	EntryTypeDirectory EntryType = "directory"
	EntryTypeSymlink   EntryType = "symlink"
)

type Info

type Info struct {
	ID     string
	Name   string
	Token  string
	Domain string
}

Info captures persistent volume metadata returned by the control plane. Token and Domain are populated by GetInfo and Create (which return VolumeAndToken) and empty on List.

func GetInfo added in v0.1.4

func GetInfo(ctx context.Context, volumeID string, opts Options) (*Info, error)

GetInfo retrieves metadata and a minted content token for volumeID using a one-shot Client built from opts.Config.

Endpoint: GET /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func List

func List(ctx context.Context, opts Options) ([]Info, error)

List returns all volumes visible to the authenticated caller using a one-shot Client built from opts.Config.

Endpoint: GET /volumes Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

type ListOptions added in v0.1.4

type ListOptions struct {
	// Depth is the number of directory levels to recurse (default: 1 when 0).
	Depth int
}

ListOptions configures directory listing in (*Volume).List.

type MakeDirOptions added in v0.1.4

type MakeDirOptions struct {
	UID  *uint32
	GID  *uint32
	Mode *uint32
	// Force creates parent directories if they do not exist (wire query param `force`).
	Force *bool
	// Parents is an alias for Force when Force is nil.
	Parents *bool
}

MakeDirOptions configures directory creation in (*Volume).MakeDirWithOptions.

type MetadataOptions added in v0.1.4

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

MetadataOptions configures ownership and permission updates in UpdateMetadata.

type Options

type Options struct {
	Config e2b.Config
}

Options configure a single package-level volume call.

type Volume

type Volume struct {
	ID     string
	Name   string
	Domain string
	// contains filtered or unexported fields
}

Volume is a handle for one persistent volume.

func Connect

func Connect(ctx context.Context, volumeID, token string, opts Options) (*Volume, error)

Connect validates that volumeID exists on the control plane and attaches to it using token (falling back to the server-minted token when token is empty). Prefer (*Client).Connect or ConnectByID when you do not already hold a token, or (*Client).ConnectWithToken for zero-RTT attachment.

Endpoint: GET /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func ConnectByID added in v0.1.4

func ConnectByID(ctx context.Context, volumeID string, cfg e2b.Config) (*Volume, error)

ConnectByID attaches to an existing volume by ID using the server-minted JWT and optional BYOC domain returned by GET /volumes/{volumeID}.

Endpoint: GET /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func ConnectWithToken added in v0.1.4

func ConnectWithToken(volumeID, token string, opts Options, domain ...string) (*Volume, error)

ConnectWithToken constructs a Volume handle locally from a pre-minted JWT without making a control-plane HTTP round-trip. An optional BYOC domain overrides opts.Config.Domain when routing volume-content requests.

func Create

func Create(ctx context.Context, name string, opts Options) (*Volume, error)

Create provisions a new volume using a one-shot Client built from opts.Config. Prefer NewClient when making multiple volume calls.

Endpoint: POST /volumes Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) Delete

func (v *Volume) Delete(ctx context.Context) error

Delete removes this volume permanently on the control plane. Deleting a volume that is already gone (HTTP 404) succeeds as a no-op; use (*Volume).Destroy or (*Client).Destroy to distinguish whether a volume existed.

Endpoint: DELETE /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) Destroy added in v0.1.4

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

Destroy permanently deletes this volume on the control plane, returning (false, nil) when the volume was already gone (HTTP 404).

Endpoint: DELETE /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) Exists added in v0.1.4

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

Exists reports whether a file, directory, or symlink exists at path. It returns (false, nil) on HTTP 404 and propagates any other error.

Endpoint: GET /volumecontent/{volumeID}/path Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) GetInfo added in v0.1.4

func (v *Volume) GetInfo(ctx context.Context) (*Info, error)

GetInfo retrieves control-plane metadata, a freshly minted content JWT, and the optional BYOC cluster domain for this volume.

Endpoint: GET /volumes/{volumeID} Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) List added in v0.1.4

func (v *Volume) List(ctx context.Context, path string, opts ...ListOptions) ([]EntryStat, error)

List returns the entries inside the directory at path. Pass ListOptions{Depth} to recurse multiple levels (default depth on the server is 1).

Endpoint: GET /volumecontent/{volumeID}/dir Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) MakeDir

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

MakeDir creates a directory at path. Use MakeDirWithOptions to configure uid, gid, mode, or parent-directory creation (`Force` / `Parents`) and inspect the resulting EntryStat.

Endpoint: POST /volumecontent/{volumeID}/dir Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) MakeDirWithOptions added in v0.1.4

func (v *Volume) MakeDirWithOptions(ctx context.Context, path string, opts MakeDirOptions) (*EntryStat, error)

MakeDirWithOptions creates a directory at path with optional ownership, permissions, and parent creation (`Force` or `Parents`), returning its EntryStat.

Endpoint: POST /volumecontent/{volumeID}/dir Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) ReadFile

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

ReadFile downloads the file at path into memory. When ctx has no deadline, a 1-hour transfer timeout (DefaultFileTransferTimeout) is applied.

Endpoint: GET /volumecontent/{volumeID}/file Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) ReadFileStream added in v0.1.4

func (v *Volume) ReadFileStream(ctx context.Context, path string) (io.ReadCloser, error)

ReadFileStream opens a streaming download for the file at path. On success (HTTP 200), the caller owns the returned io.ReadCloser and MUST close it to release the underlying connection and transfer timer.

Endpoint: GET /volumecontent/{volumeID}/file Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) ReadFileString added in v0.1.4

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

ReadFileString downloads the file at path as a UTF-8 string. When ctx has no deadline, a 1-hour transfer timeout (DefaultFileTransferTimeout) is applied.

Endpoint: GET /volumecontent/{volumeID}/file Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) Remove

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

Remove deletes a file or directory at path from the volume.

Endpoint: DELETE /volumecontent/{volumeID}/path Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) Stat added in v0.1.4

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

Stat returns metadata for the file, directory, or symlink at path. Returns an error wrapping *e2b.FileNotFoundError when path does not exist.

Endpoint: GET /volumecontent/{volumeID}/path Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) Token

func (v *Volume) Token() string

Token returns the per-volume JWT bearer token authenticating content calls. Callers can persist it and later pass it to (*Client).ConnectWithToken or Connect.

func (*Volume) UpdateMetadata added in v0.1.4

func (v *Volume) UpdateMetadata(ctx context.Context, path string, opts MetadataOptions) (*EntryStat, error)

UpdateMetadata updates uid, gid, and/or mode on path and returns the updated EntryStat.

Endpoint: PATCH /volumecontent/{volumeID}/path Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) WriteFile

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

WriteFile uploads content to path inside the volume. Use WriteFileWithOptions or WriteFileStream to set uid/gid/mode/force options or inspect the returned EntryStat.

Endpoint: PUT /volumecontent/{volumeID}/file Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) WriteFileStream added in v0.1.4

func (v *Volume) WriteFileStream(ctx context.Context, path string, r io.Reader, opts ...WriteOptions) (*EntryStat, error)

WriteFileStream streams r (`application/octet-stream`) to path inside the volume with optional uid, gid, mode, and force query parameters, returning the written file's EntryStat. When ctx has no deadline, a 1-hour transfer timeout (DefaultFileTransferTimeout) is applied.

Endpoint: PUT /volumecontent/{volumeID}/file Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

func (*Volume) WriteFileWithOptions added in v0.1.4

func (v *Volume) WriteFileWithOptions(ctx context.Context, path string, content []byte, opts WriteOptions) (*EntryStat, error)

WriteFileWithOptions uploads content to path inside the volume with optional uid, gid, mode, and force query parameters, returning the written EntryStat.

Endpoint: PUT /volumecontent/{volumeID}/file Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in runtime < 2026.07).

type WriteOptions added in v0.1.4

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

WriteOptions configures file creation/overwrite in (*Volume).WriteFileStream.

Jump to

Keyboard shortcuts

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