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
- func Destroy(ctx context.Context, volumeID string, opts Options) (bool, error)
- type Client
- func (c *Client) Config() e2b.Config
- func (c *Client) Connect(ctx context.Context, volumeID string) (*Volume, error)
- func (c *Client) ConnectWithToken(volumeID, token string, domain ...string) (*Volume, error)
- func (c *Client) Create(ctx context.Context, name string) (*Volume, error)
- func (c *Client) Destroy(ctx context.Context, volumeID string) (bool, error)
- func (c *Client) GetInfo(ctx context.Context, volumeID string) (*Info, error)
- func (c *Client) List(ctx context.Context) ([]Info, error)
- type EntryStat
- type EntryType
- type Info
- type ListOptions
- type MakeDirOptions
- type MetadataOptions
- type Options
- type Volume
- func Connect(ctx context.Context, volumeID, token string, opts Options) (*Volume, error)
- func ConnectByID(ctx context.Context, volumeID string, cfg e2b.Config) (*Volume, error)
- func ConnectWithToken(volumeID, token string, opts Options, domain ...string) (*Volume, error)
- func Create(ctx context.Context, name string, opts Options) (*Volume, error)
- func (v *Volume) Delete(ctx context.Context) error
- func (v *Volume) Destroy(ctx context.Context) (bool, error)
- func (v *Volume) Exists(ctx context.Context, path string) (bool, error)
- func (v *Volume) GetInfo(ctx context.Context) (*Info, error)
- func (v *Volume) List(ctx context.Context, path string, opts ...ListOptions) ([]EntryStat, error)
- func (v *Volume) MakeDir(ctx context.Context, path string) error
- func (v *Volume) MakeDirWithOptions(ctx context.Context, path string, opts MakeDirOptions) (*EntryStat, error)
- func (v *Volume) ReadFile(ctx context.Context, path string) ([]byte, error)
- func (v *Volume) ReadFileStream(ctx context.Context, path string) (io.ReadCloser, error)
- func (v *Volume) ReadFileString(ctx context.Context, path string) (string, error)
- func (v *Volume) Remove(ctx context.Context, path string) error
- func (v *Volume) Stat(ctx context.Context, path string) (*EntryStat, error)
- func (v *Volume) Token() string
- func (v *Volume) UpdateMetadata(ctx context.Context, path string, opts MetadataOptions) (*EntryStat, error)
- func (v *Volume) WriteFile(ctx context.Context, path string, content []byte) error
- func (v *Volume) WriteFileStream(ctx context.Context, path string, r io.Reader, opts ...WriteOptions) (*EntryStat, error)
- func (v *Volume) WriteFileWithOptions(ctx context.Context, path string, content []byte, opts WriteOptions) (*EntryStat, error)
- type WriteOptions
Examples ¶
Constants ¶
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 ¶
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
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.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/eric642/e2b-go-sdk"
"github.com/eric642/e2b-go-sdk/volume"
)
func main() {
ctx := context.Background()
client, err := volume.NewClient(e2b.Config{
APIKey: "e2b_...",
})
if err != nil {
log.Fatal(err)
}
vol, err := client.Create(ctx, "my-dataset")
if err != nil {
log.Fatal(err)
}
defer func() { _ = vol.Delete(ctx) }()
if err := vol.WriteFile(ctx, "/hello.txt", []byte("hello volume")); err != nil {
log.Fatal(err)
}
content, err := vol.ReadFileString(ctx, "/hello.txt")
if err != nil {
log.Fatal(err)
}
fmt.Println(content)
}
Output:
func (*Client) Config ¶ added in v0.1.4
Config returns a deep copy of the resolved e2b.Config backing this Client.
func (*Client) Connect ¶ added in v0.1.4
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
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.
Example ¶
package main
import (
"fmt"
"log"
"github.com/eric642/e2b-go-sdk"
"github.com/eric642/e2b-go-sdk/volume"
)
func main() {
client, err := volume.NewClient(e2b.Config{
APIKey: "example-key",
Domain: "e2b.app",
})
if err != nil {
log.Fatal(err)
}
vol, err := client.ConnectWithToken("vol-123", "example-jwt")
if err != nil {
log.Fatal(err)
}
fmt.Println(vol.ID, vol.Token() != "")
}
Output: vol-123 true
func (*Client) Create ¶ added in v0.1.4
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
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).
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.
type Info ¶
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.
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
MetadataOptions configures ownership and permission updates in UpdateMetadata.
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 ¶
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
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
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 ¶
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 ¶
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
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
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
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
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 ¶
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 ¶
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
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
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 ¶
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
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 ¶
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 ¶
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).