Typical flow
~/.microsandbox/volumes/<name>/. They persist independently of any sandbox. There is no Rust-side resource to release: Remove deletes the on-disk state and the DB record.
Functions
CreateVolume()
Example
Example
*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.Contextnamestringopts…VolumeOptionReturns
Name and Path.GetVolume()
Example
Example
ErrVolumeNotFound if no such volume exists.
Parameters
ctxcontext.ContextnamestringReturns
ListVolumes()
Example
Example
Parameters
ctxcontext.ContextReturns
RemoveVolume()
Example
Example
Parameters
ctxcontext.ContextnamestringVolume methods
AVolume is returned by CreateVolume and carries the volume’s name and host path.
v.Name()
v.Path()
v.FS()
Example
Example
*VolumeFs for direct host-side file operations on this volume.
Returns
v.Remove()
Example
Example
RemoveVolume(ctx, v.Name()).
VolumeHandle methods
AVolumeHandle is the metadata reference returned by GetVolume and ListVolumes.
h.Name()
h.Path()
h.Kind()
VolumeKindDir or VolumeKindDisk.
Returns
h.QuotaMiB()
nil if unlimited.
h.UsedBytes()
h.CapacityBytes()
nil for directory volumes.
h.DiskFormat()
nil for directory volumes.
h.DiskFstype()
nil for directory volumes.
h.Labels()
h.CreatedAt()
time.Time value if unknown.
h.FS()
*VolumeFs for direct host-side file operations on this volume.
Returns
h.Remove()
RemoveVolume(ctx, h.Name()).
VolumeFs methods
Host-side filesystem operations on a named volume’s data directory. Obtain viaVolume.FS() or VolumeHandle.FS(). These operations run directly on the host filesystem: no running sandbox is required and no agent protocol is involved.
All path arguments are relative to the volume root. Paths that would escape the root via .., absolute components, or stray symlink chains are rejected with ErrPathEscape.
vfs.Root()
vfs.Read()
Parameters
relPathstringReturns
vfs.ReadString()
vfs.Write()
0o644.
Parameters
relPathstringdata[]bytevfs.WriteString()
0o644.
vfs.Mkdir()
0o755).
vfs.Remove()
vfs.RemoveAll()
vfs.Exists()
Returns
true if a file or directory exists at the path.Options
Functional options passed toCreateVolume, plus the Mount factory helpers that attach a volume, bind mount, tmpfs, or disk image to a sandbox via WithMounts.
WithVolumeKind()
VolumeKindDir (default) and VolumeKindDisk.
Parameters
kindVolumeKindWithVolumeSize()
VolumeKindDisk.
Parameters
mebibytesuint32WithVolumeQuota()
Parameters
mebibytesuint32WithVolumeLabels()
Parameters
labelsmap[string]stringMount.Bind()
Example
Example
MountConfig for use with WithMounts.
Parameters
hostPathstringoptsMountOptionsMount.Named()
Example
Example
CreateVolume). Returns a MountConfig.
Parameters
namestringoptsMountOptionsMount.NamedWith()
Example
Example
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
namestringoptsMountOptionsnamedOptsNamedVolumeOptionsMount.Tmpfs()
Example
Example
MountConfig.
Parameters
optsTmpfsOptionsMount.Disk()
Example
Example
MountConfig.
Parameters
hostPathstringoptsDiskOptionsTypes
Volume
A named persistent volume carrying its host-side path. Returned byCreateVolume. Lookups via GetVolume and ListVolumes yield richer VolumeHandle values instead.
Returned by CreateVolume()
| Method | Returns | Description |
|---|---|---|
Name() | string | Volume name |
Path() | string | Host filesystem path of the data directory |
FS() | *VolumeFs | Host-side filesystem accessor |
Remove(ctx) | error | Delete this volume (all sandboxes using it must be stopped) |
VolumeHandle
Metadata reference for a named volume. Obtain viaGetVolume or ListVolumes.
Returned by GetVolume() · ListVolumes()
| Method | Returns | Description |
|---|---|---|
Name() | string | Volume name |
Path() | string | Host filesystem path of the data directory |
Kind() | VolumeKind | Volume kind: VolumeKindDir or VolumeKindDisk |
QuotaMiB() | *uint32 | Quota in MiB, or nil if unlimited |
UsedBytes() | uint64 | Current disk usage in bytes |
CapacityBytes() | *uint64 | Disk capacity in bytes, or nil |
DiskFormat() | *string | Disk image format, or nil |
DiskFstype() | *string | Disk filesystem type, or nil |
Labels() | map[string]string | Metadata labels |
CreatedAt() | time.Time | Creation timestamp, zero value if unknown |
FS() | *VolumeFs | Host-side filesystem accessor |
Remove(ctx) | error | Delete this volume |
VolumeFs
Host-side filesystem operations on a volume’s data directory. Obtain viaVolume.FS() or VolumeHandle.FS(). All path arguments are relative to the volume root; escaping paths are rejected with ErrPathEscape.
Returned by Volume.FS() · VolumeHandle.FS()
| Method | Returns | Description |
|---|---|---|
Root() | string | Absolute host path of the data directory |
Read(relPath) | ([]byte, error) | Read file bytes |
ReadString(relPath) | (string, error) | Read file as a UTF-8 string |
Write(relPath, data) | error | Write bytes, creating or truncating |
WriteString(relPath, content) | error | Write a string |
Mkdir(relPath) | error | Create a directory tree |
Remove(relPath) | error | Delete a file or empty directory |
RemoveAll(relPath) | error | Recursive delete |
Exists(relPath) | (bool, error) | Check for existence |
ErrPathEscape
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 byVolumeOption functions. Most callers go through CreateVolume(ctx, name, opts...); VolumeConfig is exported for callers that prefer to construct one directly.
Mutated by VolumeOption
| Field | Type | Description |
|---|---|---|
QuotaMiB | uint32 | Maximum storage size in MiB (zero = unlimited) |
Kind | VolumeKind | Volume kind (VolumeKindDir by default) |
SizeMiB | uint32 | Disk capacity in MiB for VolumeKindDisk |
Labels | map[string]string | Metadata labels |
VolumeOption
CreateVolume. Constructed by the WithVolume* helpers.
Used by CreateVolume()
VolumeKind
Used by VolumeConfig · WithVolumeKind() · VolumeHandle.Kind()
| Constant | Value | Description |
|---|---|---|
VolumeKindDir | "dir" | Directory-backed named volume |
VolumeKindDisk | "disk" | Raw ext4 disk-backed named volume |
MountConfig
Discriminated mount configuration produced by theMount factory helpers and passed to WithMounts. Construct it with the factory rather than by hand: the factory sets the internal kind discriminator and enforces the mutually-exclusive flavours. Inspect the flavour via Kind().
Returned by Mount.Bind() · Mount.Named() · Mount.NamedWith() · Mount.Tmpfs() · Mount.Disk()
| Field | Type | Description |
|---|---|---|
Bind | string | Host path for bind mounts |
Named | string | Volume name for named mounts |
NamedMode | string | Provisioning mode for named mounts ("existing", "create", "ensure-exists") |
NamedKind | string | Kind for provisioned named mounts ("dir" or "disk") |
QuotaMiB | uint32 | Quota in MiB for provisioned directory volumes |
Tmpfs | bool | Set for tmpfs mounts |
Disk | string | Host path for disk images |
Format | string | Disk format |
Fstype | string | Inner filesystem type |
Readonly | bool | Whether the mount is read-only |
Noexec | bool | Whether direct execution from the mount is disabled |
Nosuid | bool | Whether setuid/setgid elevation from files on the mount is ignored |
Nodev | bool | Whether device files on the mount are ignored |
SizeMiB | uint32 | Size limit for tmpfs / capacity for provisioned disk volumes |
StatVirtualization | StatVirtualization | Per-mount stat-virtualization policy (bind / named only) |
HostPermissions | HostPermissions | Per-mount host-permission propagation policy (bind / named only) |
| Method | Returns | Description |
|---|---|---|
Kind() | MountKind | Which mount flavour this is |
MountKind
mount.Kind().
Returned by MountConfig.Kind()
| Constant | Description |
|---|---|
MountKindBind | Host bind mount |
MountKindNamed | Named persistent volume |
MountKindTmpfs | In-memory tmpfs |
MountKindDisk | Host disk image |
MountOptions
Tuning struct forMount.Bind, Mount.Named, and Mount.NamedWith. StatVirtualization and HostPermissions are virtiofs-only and rejected at build time if combined with a tmpfs or disk-image mount; their zero values preserve the conservative defaults (strict, private).
Used by Mount.Bind() · Mount.Named() · Mount.NamedWith()
| Field | Type | Description |
|---|---|---|
Readonly | bool | Mount as read-only; virtiofs-backed mounts also reject writes in the host filesystem server |
Noexec | bool | Prevent direct execution from the mount |
Nosuid | bool | Ignore setuid and setgid privilege elevation from files on the mount |
Nodev | bool | Ignore device files on the mount |
StatVirtualization | StatVirtualization | Per-mount stat-virtualization policy (virtiofs only) |
HostPermissions | HostPermissions | Per-mount host-permission propagation policy (virtiofs only) |
NamedVolumeOptions
Tunes sandbox-time named volume provisioning forMount.NamedWith.
Used by Mount.NamedWith()
| Field | Type | Description |
|---|---|---|
Mode | string | "existing", "create", or "ensure-exists"; empty means "existing" |
Kind | string | "dir" or "disk"; empty means "dir" |
SizeMiB | uint32 | Disk capacity in MiB; required when creating or ensuring a missing disk volume |
QuotaMiB | uint32 | Directory volume quota in MiB |
TmpfsOptions
Tuning struct forMount.Tmpfs.
Used by Mount.Tmpfs()
| Field | Type | Description |
|---|---|---|
SizeMiB | uint32 | Maximum size in MiB |
Readonly | bool | Mount as read-only |
Noexec | bool | Prevent direct execution from the mount |
Nosuid | bool | Ignore setuid and setgid privilege elevation from files on the mount |
Nodev | bool | Ignore device files on the mount |
DiskOptions
Tuning struct forMount.Disk.
Used by Mount.Disk()
| Field | Type | Description |
|---|---|---|
Format | string | Format hint ("raw", "qcow2", "vmdk"). Optional; the runtime can usually probe |
Fstype | string | Inner filesystem type (e.g. "ext4", "xfs"). Optional; omitted means auto-detect |
Readonly | bool | Mount as read-only |
Noexec | bool | Prevent direct execution from the mount |
Nosuid | bool | Ignore setuid and setgid privilege elevation from files on the mount |
Nodev | bool | Ignore device files on the mount |