Volume
Named volumes are managed by microsandbox and stored by default under~/.microsandbox/volumes/<name>/. They persist independently of any sandbox.
Remove deletes the on-disk state and the DB record.
| Method | Returns | Description |
|---|---|---|
Name() | string | Volume name |
Path() | string | Host filesystem path of the volume’s data directory |
FS() | *VolumeFs | Host-side filesystem accessor |
Remove(ctx) | error | Delete this volume (all sandboxes using it must be stopped) |
Top-level functions
CreateVolume()
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | Cancels the create |
| name | string | Volume name |
| opts | ...VolumeOption | Functional options — see Options |
| Type | Description |
|---|---|
*Volume | Newly created volume with Name and Path |
ErrVolumeAlreadyExists if a volume with the given name already exists.
GetVolume()
ErrVolumeNotFound if no such volume exists.
ListVolumes()
RemoveVolume()
Options
WithVolumeQuota()
WithVolumeKind()
VolumeKindDir and VolumeKindDisk.
WithVolumeSize()
VolumeKindDisk.
WithVolumeLabels()
VolumeHandle
Metadata reference returned byGetVolume and ListVolumes.
| Method | Returns | Description |
|---|---|---|
Name() | string | Volume name |
Path() | string | Host filesystem path of the volume’s 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 |
DiskFormat() | *string | Disk image format |
DiskFstype() | *string | Disk filesystem type |
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 named volume’s data directory. Obtained 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.
Root()
Read()
ReadString()
Write()
0o644.
WriteString()
Mkdir()
0o755).
Remove()
RemoveAll()
Exists()
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.
Mounts
Volume mounts attach a host directory, named volume, tmpfs, or disk image to a guest path. Configure them viaWithMounts on the sandbox:
Mount.X(...) helper returns a MountConfig. The kind discriminator is set internally; callers should always use these helpers rather than constructing the struct manually.
Mount.Bind()
Mount.Named()
CreateVolume).
Mount.NamedWith()
NamedVolumeOptions.Mode accepts "existing" (default), "create", or "ensure-exists". NamedVolumeOptions.Kind accepts "dir" (default) or "disk".
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. The ensure-exists mode errors when the existing volume has a different kind, quota, or capacity than the requested configuration; it does not mutate existing volume metadata.
NamedVolumeOptions
| Field | Description |
|---|---|
Mode | "existing", "create", or "ensure-exists"; empty means "existing" |
Kind | "dir" or "disk"; empty means "dir" |
SizeMiB | Disk capacity in MiB; required when creating or ensuring a missing disk volume |
QuotaMiB | Directory volume quota in MiB |
Mount.Tmpfs()
Mount.Disk()
Mount option types
MountOptions
Tuning struct forMount.Bind and Mount.Named.
| 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 |
TmpfsOptions
Tuning struct forMount.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.
| Field | Type | Description |
|---|---|---|
| Format | string | Format hint ("raw", "qcow2", "vmdk"). Optional; defaults from the file extension |
| 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 |
MountConfig
Discriminated mount configuration produced byMount helpers. Inspect the kind via Kind().
| Field | Type | Description |
|---|---|---|
| Bind | string | Host path for bind mounts |
| Named | string | Volume name for named mounts |
| 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 privilege elevation from files on the mount is ignored |
| Nodev | bool | Whether device files on the mount are ignored |
| SizeMiB | uint32 | Size limit for tmpfs mounts |
MountKind
| Constant | Description |
|---|---|
MountKindBind | Host bind mount |
MountKindNamed | Named persistent volume |
MountKindTmpfs | In-memory tmpfs |
MountKindDisk | Host disk image |
mount.Kind().
Types
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.
| Field | Type | Description |
|---|---|---|
| Kind | VolumeKind | Volume kind (VolumeKindDir by default) |
| QuotaMiB | uint32 | Maximum storage size in MiB (zero = unlimited) |
| SizeMiB | uint32 | Disk capacity in MiB for VolumeKindDisk |
| Labels | map[string]string | Metadata labels |
VolumeOption
CreateVolume.