Typical flow
Static methods
Static methods onVolume that manage named persistent volumes. Volumes live independently of any sandbox, stored by default under ~/.microsandbox/volumes/<name>/.
Volume.create()
Example
Example
"dir" volume is a host directory; a "disk" volume is a backing disk image that requires size_mib.
Parameters
namestrVolume name.
kindstrVolume kind:
“dir” (default) or “disk”.size_mibint | NoneDisk capacity in MiB; required with
kind=“disk”.quota_mibint | NoneQuota in MiB recorded for directory volumes.
labelsdict[str, str] | NoneMetadata labels.
Returns
Created volume, exposing
name and path.Volume.get()
Example
Example
Parameters
namestrVolume name.
Returns
Handle with metadata and a filesystem accessor.
Volume.list()
Example
Example
Returns
All volume handles.
Volume.remove()
Example
Example
Parameters
namestrVolume name.
Mount factories
Static factory methods onVolume that build a MountConfig. Pass the result as a value in the volumes dict when creating a sandbox, keyed by the guest mount point.
Volume.bind()
Example
Example
Parameters
pathstrDirectory path on the host.
readonlyboolMount as read-only; virtiofs-backed mounts also reject writes in the host filesystem server.
noexecboolPrevent direct execution from the mount.
nosuidboolIgnore setuid and setgid privilege elevation from files on the mount.
nodevboolIgnore device files on the mount.
Returns
Mount configuration.
Volume.named()
Example
Example
Volume.create().
Parameters
namestrVolume name.
readonlyboolMount as read-only; virtiofs-backed mounts also reject writes in the host filesystem server.
noexecboolPrevent direct execution from the mount.
nosuidboolIgnore setuid and setgid privilege elevation from files on the mount.
nodevboolIgnore device files on the mount.
Returns
Mount configuration.
Volume.tmpfs()
Example
Example
Parameters
size_mibint | NoneMaximum size in MiB.
readonlyboolMount as read-only.
noexecboolPrevent direct execution from the mount.
nosuidboolIgnore setuid and setgid privilege elevation from files on the mount.
nodevboolIgnore device files on the mount.
Returns
Mount configuration.
Volume.disk()
Example
Example
format is the disk image format ("qcow2", "raw", or "vmdk"); when omitted it is inferred from the file extension. fstype (e.g. "ext4") is the inner filesystem agentd mounts; when omitted, agentd probes /proc/filesystems for a type that mounts cleanly.
Parameters
pathstrHost path to the disk image.
formatstr | NoneDisk image format hint. See DiskImageFormat.
fstypestr | NoneInner filesystem type.
readonlyboolMount as read-only.
noexecboolPrevent direct execution from the mount.
nosuidboolIgnore setuid and setgid privilege elevation from files on the mount.
nodevboolIgnore device files on the mount.
Returns
Mount configuration.
Instance properties
Read-only properties on aVolume returned by Volume.create().
volume.name
volume.path
VolumeFs methods
Host-side filesystem operations on a named volume, obtained via thefs property on a VolumeHandle. These run directly on the host filesystem; no running sandbox is required. All paths are relative to the volume root.
fs.read()
Example
Example
Parameters
pathstrPath relative to the volume root.
Returns
bytes
File contents as raw bytes.
fs.read_text()
Parameters
pathstrPath relative to the volume root.
Returns
str
File contents as a string.
fs.write()
Example
Example
Parameters
pathstrPath relative to the volume root.
databytesFile content.
fs.list()
Parameters
pathstrPath relative to the volume root.
Returns
Directory entries.
fs.mkdir()
Parameters
pathstrPath relative to the volume root.
fs.remove_file()
Parameters
pathstrPath relative to the volume root.
fs.exists()
Parameters
pathstrPath relative to the volume root.
Returns
bool
True if the path exists.Types
VolumeHandle
Returned by Volume.get(), Volume.list()
A lightweight handle to a named volume, with its database metadata and a host-side filesystem accessor.| Property / Method | Type | Description |
|---|---|---|
| name | str | Volume name |
| kind | str | Volume kind: dir or disk |
| quota_mib | int | None | Storage quota in MiB |
| used_bytes | int | Current disk usage in bytes |
| capacity_bytes | int | None | Disk capacity in bytes |
| disk_format | str | None | Disk image format |
| disk_fstype | str | None | Disk filesystem type |
| labels | dict[str, str] | Metadata labels |
| created_at | float | None | Creation timestamp (ms since epoch) |
| fs | VolumeFs | Host-side filesystem handle |
| remove() | (async) None | Delete this volume |
VolumeFs
Returned by VolumeHandle.fs
Host-side filesystem operations on a named volume. No running sandbox is required. See the VolumeFs methods above for the full API.| Method | Signature | Description |
|---|---|---|
| read | read(path) -> bytes | Read a file as raw bytes |
| read_text | read_text(path) -> str | Read a file as UTF-8 text |
| write | write(path, data) -> None | Write bytes to a file |
| list | list(path) -> list[FsEntry] | List a directory |
| mkdir | mkdir(path) -> None | Create a directory |
| remove_file | remove_file(path) -> None | Remove a file |
| exists | exists(path) -> bool | Check a path exists |
MountConfig
Returned by Volume.bind(), Volume.named(), Volume.tmpfs(), Volume.disk()
Frozen dataclass representing a mount configuration. Build one with a mount factory and pass it as a value in the sandboxvolumes dict. stat_virtualization and host_permissions apply only to virtiofs-backed mounts (BIND and NAMED); setting either on a TMPFS or DISK mount raises ValueError.
| Field | Type | Default | Description |
|---|---|---|---|
| kind | MountKind | - | Type of mount (required) |
| bind | str | None | None | Host path for bind mounts |
| named | str | None | None | Volume name for named mounts |
| named_mode | "existing" | "create" | "ensure-exists" | None | None | Named-volume creation behavior |
| named_kind | "dir" | "directory" | "disk" | None | None | Storage kind for created named volumes |
| quota_mib | int | None | None | Quota in MiB for directory named volumes |
| size_mib | int | None | None | Size limit for tmpfs, or capacity for disk named volumes |
| readonly | bool | False | Whether the mount is read-only |
| noexec | bool | False | Whether direct execution from the mount is disabled |
| nosuid | bool | False | Whether setuid/setgid privilege elevation is ignored |
| nodev | bool | False | Whether device files on the mount are ignored |
| disk | str | None | None | Host path to a disk image for disk mounts |
| format | DiskImageFormat | str | None | None | Disk image format for disk mounts |
| fstype | str | None | None | Inner filesystem type for disk mounts |
| stat_virtualization | StatVirtualization | str | None | None | Per-mount stat-virtualization policy (virtiofs-backed only) |
| host_permissions | HostPermissions | str | None | None | Per-mount host-permission policy (virtiofs-backed only) |
MountKind
Used by MountConfig
String enum (StrEnum) for the type of mount.
| Value | Description |
|---|---|
"bind" | Host bind mount |
"named" | Named volume mount |
"tmpfs" | In-memory filesystem |
"disk" | Host disk image mount |
DiskImageFormat
Used by Volume.disk(), MountConfig
String enum (StrEnum) for the format of a backing disk image.
| Value | Description |
|---|---|
"qcow2" | QEMU copy-on-write v2 image |
"raw" | Raw disk image |
"vmdk" | VMware disk image |