Typical flow
Static methods
Volume::builder()
Example
Example
.disk() then .size() for a raw ext4 disk-image volume. Volume names must start with an alphanumeric character and contain only alphanumeric characters, dots, hyphens, and underscores. See VolumeBuilder for all options.
Parameters
nameimpl Into<String>“pip-cache”.Returns
Volume::create()
Example
Example
VolumeConfig. Routes through the active backend. Locally this inserts a database record and creates the host directory (formatting a disk.raw for disk volumes). Fails with VolumeAlreadyExists if a volume of the same name already exists. Most callers use Volume::builder(), which calls this internally.
Parameters
configVolumeConfigVolumeConfig is an alias for VolumeSpec.Returns
Volume::get()
Example
Example
VolumeNotFound if no volume by that name exists.
Parameters
name&strReturns
Volume::list()
Example
Example
Returns
Volume::remove()
Example
Example
VolumeNotFound if the volume does not exist.
Parameters
name&strVolume instance methods
A liveVolume, returned by Volume::create() or VolumeBuilder::create(). Carries the backend it was created on.
vol.name()
Returns
vol.kind()
Directory or Disk.
Returns
vol.fs()
Example
Example
tokio::fs. See VolumeFs for the operations.
Returns
vol.path()
Example
Example
Unsupported for cloud volumes, whose bytes live in the org’s object storage rather than on the caller’s host.
Returns
~/.microsandbox/volumes/pip-cache/.vol.disk_path()
disk.raw) for disk volumes. Returns None for directory volumes.
Returns
disk.raw, or None for directory volumes.vol.capacity_bytes()
None for directory volumes.
Returns
None.vol.disk_format()
"raw" for managed disk volumes). None for directory volumes.
Returns
None.vol.disk_fstype()
"ext4" for managed disk volumes). None for directory volumes.
Returns
None.vol.backend_kind()
Local or Cloud.
Returns
Local or Cloud.vol.local()
Some for local-backed volumes, None for cloud-backed ones.
Returns
None.vol.cloud()
Some for cloud-backed volumes, None for local-backed ones.
Returns
None.VolumeHandle methods
A lightweight handle returned byVolume::get() and Volume::list(). Exposes metadata captured at read time plus filesystem and delete operations, without holding a live Volume.
h.name()
Returns
h.kind()
Directory or Disk.
Returns
h.fs()
Example
Example
VolumeFs.
Returns
h.remove()
Example
Example
h.used_bytes()
Volume::get() again for a fresh reading.
Returns
h.quota_mib()
None if unlimited.
Returns
None.h.capacity_bytes()
None for directory volumes.
Returns
None.h.disk_format()
None for directory volumes.
Returns
None.h.disk_fstype()
None for directory volumes.
Returns
None.h.disk_path()
disk.raw) for local disk volumes. None otherwise.
Returns
disk.raw, or None.h.labels()
Returns
h.created_at()
Returns
None.h.backend_kind()
Local or Cloud.
Returns
Local or Cloud.h.local()
Some for local-backed handles, None for cloud-backed ones.
Returns
None.h.cloud()
Some for cloud-backed handles, None for local-backed ones.
Returns
None.VolumeFs methods
Host-side filesystem operations on a named volume, obtained viaVolume::fs() or VolumeHandle::fs(). Unlike SandboxFsOps, which goes through the agent protocol, VolumeFs reads and writes the volume’s bytes directly. Paths are relative to the volume root; a leading / is stripped, and path traversal outside the root is rejected.
fs.read()
Example
Example
Parameters
path&strReturns
fs.read_to_string()
Example
Example
Parameters
path&strReturns
fs.read_stream()
Example
Example
VolumeFsReadStream that yields 64 KiB chunks, so large files don’t have to be held in memory at once.
Parameters
path&strReturns
fs.write()
Example
Example
Parameters
path&strdataimpl AsRef<[u8]>fs.write_stream()
Example
Example
VolumeFsWriteSink that accepts chunks of bytes. Creates parent directories as needed.
Parameters
path&strReturns
fs.list()
Example
Example
Parameters
path&strReturns
fs.mkdir()
Example
Example
Parameters
path&strfs.remove()
Example
Example
remove_dir() for directories.
Parameters
path&strfs.remove_dir()
Example
Example
Parameters
path&strfs.copy()
Example
Example
Parameters
from&strto&strfs.rename()
Example
Example
Parameters
from&strto&strfs.stat()
Example
Example
Parameters
path&strReturns
fs.exists()
Example
Example
false rather than an error if the path is absent.
Parameters
path&strReturns
true if the path exists.VolumeBuilder
Builder for configuring a named volume before creation. Obtained viaVolume::builder(name). Directory-backed is the default; disk volumes require .disk() plus .size(). Every setter returns Self, so calls chain.
.directory()
.disk()
.size().
.size()
Example
Example
u32 (MiB) or a SizeExt helper such as 20.gib().
Parameters
sizeimpl Into<Mebibytes>.quota()
u32 (MiB) or a SizeExt helper such as 1.gib(). Omit for unlimited growth (the default). Rejected for disk volumes, which size up front via .size().
Parameters
sizeimpl Into<Mebibytes>.label()
Parameters
keyimpl Into<String>valueimpl Into<String>.build()
VolumeConfig without creating the volume. Pass the result to Volume::create() to provision it later.
Returns
.create()
Example
Example
Volume::create(self.build()).
Returns
MountBuilder
Builder for configuring a volume mount on a sandbox. Used inSandboxBuilder::volume(guest_path, |v| v...) (see .volume()). Pick exactly one mount kind: .bind(), .named() / .named_with(), .tmpfs(), or .disk(). Kind-specific options are validated when the surrounding SandboxBuilder is finalized, so an option set on the wrong kind surfaces a clear error rather than being silently dropped.
.bind()
,, :, or ;.
Parameters
hostimpl Into<PathBuf>.named()
Volume::create(). The volume must already exist. Persists across sandbox restarts and can be shared between sandboxes. For sandbox-time provisioning, use .named_with().
Parameters
nameimpl Into<String>.named_with()
Example
Example
NamedVolumeBuilder closure. existing (the default) behaves like .named(); create provisions the volume and fails if it already exists; ensure_exists provisions it if missing or reuses a compatible existing volume. The ensure-exists mode validates existing metadata and errors when the kind, quota, capacity, or explicitly requested labels differ; it does not mutate existing metadata.
Parameters
nameimpl Into<String>.tmpfs()
.size().
.disk()
.qcow2, .vmdk; anything else is Raw). Override with .format().
Parameters
hostimpl Into<PathBuf>.format()
.disk() mount. Valid only with .disk(); calling it on a bind, named, or tmpfs mount errors when the SandboxBuilder is finalized.
Parameters
formatDiskImageFormat.fstype()
.disk() mount, for example "ext4". If omitted, agentd probes /proc/filesystems and uses the first type that mounts cleanly. Empty values and the separators ,, ;, :, = are rejected. Valid only with .disk().
Parameters
fstypeimpl Into<String>.readonly()
EROFS).
.noexec()
sh /mnt/script.sh, because the interpreter binary executes from a different filesystem.
.nosuid()
.nodev()
.stat_virtualization()
Strict. Valid only for bind and directory-backed named-volume mounts. Tmpfs and disk-image mounts are rejected when the mount is built; disk-backed named volumes are rejected once the backing volume kind is known during sandbox create or start.
Parameters
policyStatVirtualization.host_permissions()
Private. Valid only for bind and directory-backed named-volume mounts. Combining StatVirtualization::Off with HostPermissions::Mirror is rejected, since with no overlay the guest chmod already hits the host inode and Mirror would be a no-op.
Parameters
policyHostPermissions.size()
.tmpfs() mount. Accepts a bare u32 (MiB) or a SizeExt helper such as 1.gib(). Valid only for tmpfs mounts.
Parameters
sizeimpl Into<Mebibytes>.build()
SandboxBuilder::volume; call it directly only when assembling a VolumeMount by hand. Errors when no mount kind is set, the guest path is not absolute or is /, or a kind-specific option was set on the wrong mount kind.
Returns
NamedVolumeBuilder
Sub-builder forMountBuilder::named_with(). Selects the sandbox-time existence behavior and, for create / ensure_exists, the creation metadata. Defaults to existing and directory-backed.
.existing()
.create()
.ensure_exists()
.name()
named_with().
Parameters
nameimpl Into<String>.directory()
.disk()
.size(). Clears any previously set quota.
.size()
u32 (MiB) or a SizeExt helper.
Parameters
sizeimpl Into<Mebibytes>.quota()
u32 (MiB) or a SizeExt helper.
Parameters
sizeimpl Into<Mebibytes>.label()
ensure_exists, requested labels must match the existing volume. Can be called multiple times.
Parameters
keyimpl Into<String>valueimpl Into<String>Types
Volume
A live named volume, carrying the backend it was created on. Returned byVolume::create() and VolumeBuilder::create().
Returned by Volume::create() · VolumeBuilder::create()
| Method | Returns | Description |
|---|---|---|
name() | &str | Volume name |
kind() | VolumeKind | Directory or disk |
fs() | VolumeFs | Host-side filesystem handle |
path() | MicrosandboxResult<&Path> | Host data directory (local only) |
disk_path() | Option<PathBuf> | Host disk.raw path for disk volumes |
capacity_bytes() | Option<u64> | Disk capacity in bytes |
disk_format() | Option<&str> | Disk image format |
disk_fstype() | Option<&str> | Inner disk filesystem |
backend_kind() | BackendKind | Local or cloud |
local() | Option<&VolumeLocalState> | Local-only state |
cloud() | Option<&VolumeCloudState> | Cloud-only state |
VolumeHandle
A lightweight handle to a volume, exposing metadata plus filesystem and delete operations without a liveVolume.
Returned by Volume::get() · Volume::list()
| Method | Returns | Description |
|---|---|---|
name() | &str | Volume name |
kind() | VolumeKind | Directory or disk |
fs() | VolumeFs | Host-side filesystem handle |
remove() | MicrosandboxResult<()> | Delete this volume |
used_bytes() | u64 | Usage snapshot at read time |
quota_mib() | Option<u32> | Storage quota in MiB |
capacity_bytes() | Option<u64> | Disk capacity in bytes |
disk_format() | Option<&str> | Disk image format |
disk_fstype() | Option<&str> | Inner disk filesystem |
disk_path() | Option<PathBuf> | Host disk.raw path |
labels() | &[(String, String)] | Key-value labels |
created_at() | Option<DateTime<Utc>> | Creation time |
backend_kind() | BackendKind | Local or cloud |
local() | Option<&VolumeHandleLocalState> | Local-only state |
cloud() | Option<&VolumeHandleCloudState> | Cloud-only state |
VolumeBuilder
Builder for configuring a named volume before creation. ImplementsFrom<VolumeConfig>.
Returned by Volume::builder()
| Method | Returns | Description |
|---|---|---|
directory() | Self | Directory-backed (default) |
disk() | Self | Raw ext4 disk-image volume |
size() | Self | Disk capacity (required for disk) |
quota() | Self | Directory storage quota |
label() | Self | Attach a label |
build() | VolumeConfig | Materialize config |
create() | Volume | Create the volume |
VolumeFs
Host-side filesystem operations on a volume. Borrows the parent’s backend and name and dispatches each op through the backend. A lifetime-bound handle (VolumeFs<'_>).
Returned by Volume::fs() · VolumeHandle::fs()
| Method | Returns | Description |
|---|---|---|
read() | Bytes | Read bytes |
read_to_string() | String | Read UTF-8 text |
read_stream() | VolumeFsReadStream | Stream a file in |
write() | () | Write bytes |
write_stream() | VolumeFsWriteSink | Stream a file out |
list() | Vec<FsEntry> | List a directory |
mkdir() | () | Create a directory |
remove() | () | Delete a file |
remove_dir() | () | Delete a directory recursively |
copy() | () | Copy a file |
rename() | () | Rename / move |
stat() | FsMetadata | Metadata |
exists() | bool | Existence check |
VolumeFs::with_backend(backend, name) is also available as a public constructor for FFI shims that re-assemble a handle per call; most callers use Volume::fs() / VolumeHandle::fs().
VolumeFsReadStream
A streaming reader for file data from a local volume directory. Returned byVolumeFs::read_stream().
Returned by VolumeFs::read_stream()
| Method | Returns | Description |
|---|---|---|
recv() | Option<Bytes> | Next chunk; None at EOF |
collect() | Bytes | Read the rest into one buffer |
VolumeFsWriteSink
A streaming writer for file data to a local volume directory. Returned byVolumeFs::write_stream().
Returned by VolumeFs::write_stream()
| Method | Returns | Description |
|---|---|---|
write(data) | () | Append a chunk |
close() | () | Flush and close |
MountBuilder
Builder for a sandbox volume mount, used inSandboxBuilder::volume. Builds a VolumeMount.
Used by SandboxBuilder::volume()
| Method | Returns | Description |
|---|---|---|
bind() | Self | Bind a host directory |
named() | Self | Mount an existing named volume |
named_with() | Self | Mount with sandbox-time provisioning |
tmpfs() | Self | In-memory filesystem |
disk() | Self | Host disk image as virtio-blk |
format() | Self | Disk image format (disk only) |
fstype() | Self | Inner filesystem type (disk only) |
readonly() | Self | Block writes |
noexec() | Self | Block direct execution |
nosuid() | Self | Ignore setuid/setgid |
nodev() | Self | Ignore device files |
stat_virtualization() | Self | Stat virtualization policy (virtiofs) |
host_permissions() | Self | Host permission policy (virtiofs) |
size() | Self | tmpfs size limit |
build() | MicrosandboxResult<VolumeMount> | Validate and materialize |
NamedVolumeBuilder
Sub-builder forMountBuilder::named_with(). Selects sandbox-time existence behavior and creation metadata.
Used by MountBuilder::named_with()
| Method | Returns | Description |
|---|---|---|
existing() | Self | Require the volume to exist (default) |
create() | Self | Create, fail if it exists |
ensure_exists() | Self | Create if missing, else reuse |
name() | Self | Override the volume name |
directory() | Self | Directory-backed (default) |
disk() | Self | Disk-backed; requires size |
size() | Self | Disk capacity |
quota() | Self | Directory quota |
label() | Self | Attach a label |
VolumeKind
Storage kind for a named volume.Returned by Volume::kind() · VolumeHandle::kind()
| Variant | Description |
|---|---|
Directory | Directory-backed volume mounted through virtiofs |
Disk | Raw ext4 disk-image volume mounted through virtio-blk |
VolumeSpec
Configuration for creating a named volume. Re-exported as bothVolumeSpec and the alias VolumeConfig.
Used by Volume::create() · returned by VolumeBuilder::build()
| Field | Type | Description |
|---|---|---|
name | String | Volume name |
kind | VolumeKind | Storage kind |
quota_mib | Option<u32> | Size quota in MiB; None is unlimited |
capacity_mib | Option<u32> | Disk capacity in MiB; required for disk volumes |
labels | Vec<(String, String)> | Organization labels |
MountOptions
Guest mount behavior shared by every mount kind. Set via theMountBuilder toggles; all fields default to false.
| Field | Type | Description |
|---|---|---|
readonly | bool | Guest writes fail; virtiofs mounts also reject host-side writes |
noexec | bool | Direct execution from the mount is disabled |
nosuid | bool | setuid/setgid elevation from files on the mount is ignored |
nodev | bool | Device files on the mount are ignored |
StatVirtualization
Stat virtualization policy for a virtiofs-backed mount. Default:Strict. Set via MountBuilder::stat_virtualization().
| Variant | Description |
|---|---|
Strict | Fail-closed: probe the host backing path; require xattr support |
Relaxed | Opportunistic: apply the overlay when present; tolerate missing xattr support |
Off | Literal host metadata: do not read or apply the override xattr |
HostPermissions
Host permission propagation policy for a virtiofs-backed mount. Default:Private. Set via MountBuilder::host_permissions().
| Variant | Description |
|---|---|
Private | Guest chmod stays in the metadata overlay only |
Mirror | Mirror ordinary rwx bits for files and directories to the host inode |
DiskImageFormat
Disk image format for virtio-blk root filesystems and volume mounts. Used byMountBuilder::format().
| Variant | Description |
|---|---|
Qcow2 | QEMU Copy-on-Write v2 |
Raw | Raw disk image |
Vmdk | VMware Disk (FLAT/ZERO only, no delta links) |
NamedVolumeMode
Sandbox-time behavior for a named volume mount, chosen viaNamedVolumeBuilder.
| Variant | Description |
|---|---|
Existing | Require the named volume to already exist (default) |
Create | Create the named volume and fail if it already exists |
EnsureExists | Ensure the volume exists, or reuse a compatible existing one |