Skip to main content
Create, manage, and mount named volumes. See Volumes for usage examples.

Functions

GetDefaultVolume()

Get the Cloud account’s always-present default volume. It has no user-assigned name, cannot be removed, and supports direct filesystem operations through FS(). The local backend returns ErrUnsupportedOperation; it never substitutes a directory from the caller’s machine.

CreateVolume()

Create a named volume and return a populated *Volume with its name and host path. Configure the kind, quota, disk size, and labels with option functions. Returns ErrVolumeAlreadyExists if a volume with the given name already exists.

Parameters

ctxcontext.Context
Cancels the create.
namestring
Volume name.
Functional options, see Options.

Returns

Newly created volume with Name and Path.

GetVolume()

Look up a volume by name and return its metadata. Returns ErrVolumeNotFound if no such volume exists.

Parameters

ctxcontext.Context
Cancels the lookup.
namestring
Volume name.

Returns

Metadata reference for the volume.

ListVolumes()

Return metadata for every named volume on the host.

Parameters

ctxcontext.Context
Cancels the listing.

Returns

All volume metadata handles.

RemoveVolume()

Delete a volume by name. All sandboxes referencing the volume must be stopped first.

Parameters

ctxcontext.Context
Cancels the removal.
namestring
Volume name.

Volume

Returned by CreateVolume()

A named persistent volume.

v.Name()

Return the volume’s name.

v.Path()

Return the host filesystem path of the volume’s data directory.

v.FS()

Return a *VolumeFs for direct file operations. Local calls use the managed host directory; Cloud calls use the authenticated volume API.

Returns

Filesystem accessor rooted at the volume directory.

v.Remove()

Delete this volume. All sandboxes using it must be stopped. Equivalent to RemoveVolume(ctx, v.Name()).

VolumeHandle

Metadata reference for a named volume. Obtain via GetVolume or ListVolumes.

Returned by GetVolume() · ListVolumes()

A VolumeHandle is the metadata reference returned by GetVolume and ListVolumes.

h.Name()

Return the volume name.

h.Path()

Return the host filesystem path of the volume’s data directory.

h.Kind()

Return the volume storage kind: VolumeKindDir or VolumeKindDisk.

Returns

Storage backing for the volume.

h.QuotaMiB()

Return the quota in MiB, or nil if unlimited.

h.UsedBytes()

Return the amount of space used by the volume, in bytes.

h.CapacityBytes()

Return the disk capacity in bytes for disk volumes, or nil for directory volumes.

h.DiskFormat()

Return the disk image format for disk volumes, or nil for directory volumes.

h.DiskFstype()

Return the inner filesystem type for disk volumes, or nil for directory volumes.

h.Labels()

Return the labels attached to this volume.

h.CreatedAt()

Return the creation timestamp, or the zero time.Time value if unknown.

h.FS()

Return a *VolumeFs for direct host-side file operations on this volume.

Returns

Filesystem accessor rooted at the volume directory.

h.Remove()

Delete this volume. All sandboxes using it must be stopped. Equivalent to RemoveVolume(ctx, h.Name()).

VolumeFs

Returned by Volume.FS() · VolumeHandle.FS()

Host-side filesystem operations for a named volume.

vfs.Root()

Return the absolute host path of the volume’s data directory.

vfs.Read()

Read the contents of a file relative to the volume root.

Parameters

relPathstring
Path relative to the volume root.

Returns

[]byte
File contents.

vfs.ReadString()

Read a file and return its contents as a UTF-8 string.

vfs.Write()

Write data to a file, creating or truncating it. Created files use mode 0o644.

Parameters

relPathstring
Path relative to the volume root.
data[]byte
Bytes to write.

vfs.WriteString()

Write a string to a file. Created files use mode 0o644.

vfs.Mkdir()

Create a directory and all missing parents (mode 0o755).

vfs.Remove()

Delete a single file or empty directory.

vfs.RemoveAll()

Delete a path and any children it contains (recursive).

vfs.Exists()

Report whether a file or directory exists at the given path.

Returns

bool
true if a file or directory exists at the path.

Options

Functional options passed to CreateVolume, plus the Mount factory helpers that attach a volume, bind mount, tmpfs, or disk image to a sandbox via WithMounts.

WithVolumeKind()

Select the volume kind. Valid values are VolumeKindDir (default) and VolumeKindDisk.

Parameters

Storage backing for the volume.

WithVolumeSize()

Set disk volume capacity in MiB. Required when the kind is VolumeKindDisk.

Parameters

mebibytesuint32
Disk capacity in MiB.

WithVolumeQuota()

Set the recorded quota in MiB for directory volumes. Zero means unlimited.

Parameters

mebibytesuint32
Quota in MiB; zero means unlimited.

WithVolumeLabels()

Attach key-value labels to the volume. When called repeatedly, the maps merge; later keys overwrite earlier ones.

Parameters

labelsmap[string]string
Metadata labels to attach.

Mount

Mount.Bind()

Bind-mount a host directory into the sandbox. Changes in the guest are reflected on the host and vice versa. Set MountOptions.QuotaMiB to bound how much the guest may write beyond the host directory’s existing contents, overriding the runtime’s protective default. Returns a MountConfig for use with WithMounts.

Parameters

hostPathstring
Host directory to bind.
Mount tuning (read-only, noexec, and so on).

Mount.Named()

Mount an existing named persistent volume. The volume must already exist (create it with CreateVolume). Returns a MountConfig.

Parameters

namestring
Name of an existing volume.
Mount tuning.

Mount.NamedWith()

Mount a named persistent volume with explicit sandbox-time existence behavior. NamedVolumeOptions.Mode accepts "existing" (default), "create", or "ensure-exists". Mode: "create" fails when the named volume already exists. Mode: "ensure-exists" creates the volume if it is missing and reuses a compatible existing volume; it errors when the existing volume has a different kind, quota, or capacity than requested, and never mutates existing volume metadata.

Parameters

namestring
Volume name.
Mount tuning.
Provisioning mode, kind, size, and quota.

Mount.Tmpfs()

Mount an ephemeral in-memory filesystem. Contents are discarded when the sandbox stops. Returns a MountConfig.

Parameters

Size limit and mount flags.

Mount.Disk()

Mount a host disk image as a virtio-blk device. Supports raw, qcow2, and vmdk formats. Returns a MountConfig.

Parameters

hostPathstring
Host path to the disk image.
Format, inner filesystem, and mount flags.

MountConfig

Mount configuration produced by the Mount factory.

Returned by Mount.Bind() · Mount.Named() · Mount.NamedWith() · Mount.Tmpfs() · Mount.Disk()

mount.Bind

string Host path for bind mounts

mount.Named

string Volume name for named mounts

mount.NamedMode

string Provisioning mode for named mounts ("existing", "create", "ensure-exists")

mount.NamedKind

string Kind for provisioned named mounts ("dir" or "disk")

mount.QuotaMiB

uint32 Quota in MiB for provisioned directory volumes

mount.Tmpfs

bool Set for tmpfs mounts

mount.Disk

string Host path for disk images

mount.Format

string Disk format

mount.Fstype

string Inner filesystem type

mount.Readonly

bool Whether the mount is read-only

mount.Noexec

bool Whether direct execution from the mount is disabled

mount.Nosuid

bool Whether setuid/setgid elevation from files on the mount is ignored

mount.Nodev

bool Whether device files on the mount are ignored

mount.SizeMiB

uint32 Size limit for tmpfs / capacity for provisioned disk volumes

mount.StatVirtualization

StatVirtualization Per-mount stat-virtualization policy (bind / named only)

mount.HostPermissions

HostPermissions Per-mount host-permission propagation policy (bind / named only)

mount.Owner

*MountOwner Guest owner fallback for host files without a per-file stat override (bind / directory-backed named only)

mount.Kind()

Which mount flavour this is

Returns

MountKind

Types

ErrPathEscape

Returned by every VolumeFs method when relPath is absolute, contains a .. sequence that resolves outside the volume root, or otherwise escapes the volume’s directory after filepath.Clean.

Returned by VolumeFs methods

VolumeConfig

The config struct populated by VolumeOption functions. Most callers go through CreateVolume(ctx, name, opts...); VolumeConfig is exported for callers that prefer to construct one directly.

Mutated by VolumeOption

VolumeOption

A functional option for CreateVolume. Constructed by the WithVolume* helpers.

Used by CreateVolume()

VolumeKind

Describes the storage backing for a named volume.

Used by VolumeConfig · WithVolumeKind() · VolumeHandle.Kind()

MountKind

Discriminates between the four mount flavours. Inspect via mount.Kind().

Returned by MountConfig.Kind()

MountOptions

Tuning struct for Mount.Bind, Mount.Named, and Mount.NamedWith. StatVirtualization, HostPermissions, and Owner are virtiofs-only; owner is rejected for disk-backed named volumes and when stat virtualization is off. Zero policy values preserve the conservative defaults (strict, private), while a nil owner keeps the runtime fallback identity.

Used by Mount.Bind() · Mount.Named() · Mount.NamedWith()

MountOwner

An inseparable guest ownership pair used by MountOptions.Owner. UID and GID may include zero; using a pointer to MountOwner keeps an unset owner distinct from root.

NamedVolumeOptions

Tunes sandbox-time named volume provisioning for Mount.NamedWith.

Used by Mount.NamedWith()

TmpfsOptions

Tuning struct for Mount.Tmpfs.

Used by Mount.Tmpfs()

DiskOptions

Tuning struct for Mount.Disk.

Used by Mount.Disk()