Skip to main content
See Volumes for usage examples.

Volume

Volume::local()

Select the default-local destination. Requires the local feature. Does not consult remote selection variables. See selector examples.

Volume::remote()

Capture remote environment credentials and endpoint without network I/O. Requires the cloud feature. Missing credentials fail; existing resources keep their destination. See selector examples. Creation, lookup and list items return the same Volume type. Each resource retains its context and stable identity; dropping it does not delete its storage.

vol.id()

Borrow the opaque identity without I/O. Removing and recreating a name creates a different resource identity. The identity belongs to the connection that created it.

vol.context()

Get the connection used by this volume without contacting the backend.

Volume::ctx()

Select an explicit destination. The returned collection, builders and resources retain the context’s shared state.

Volume::get_default()

Get your managed cloud organization’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 a typed Unsupported error; it never substitutes a directory from the caller’s machine.

Volume::builder()

Create a builder for configuring a new named volume. Directory-backed volumes are the default; call .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>
Volume name, e.g. “pip-cache”.

Returns

Builder for configuring the volume.

Volume::create()

Provision a volume from a 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

Volume configuration. VolumeConfig is an alias for VolumeSpec.

Returns

The created volume.

Volume::get()

Get an existing named volume. Use the resource to access the volume’s filesystem from the host, read its metadata, or delete it. Fails with VolumeNotFound if no volume by that name exists.

Parameters

name&str
Volume name.

Returns

Volume for host-side operations.

Volume::list()

List all named volumes, newest first.

Returns

All volumes.

Volume::remove()

Delete a named volume and its contents from disk. Locally, files are deleted before the database record so interrupted removal can be retried. Fails with VolumeNotFound if the volume does not exist.

Parameters

name&str
Volume name.

Instance methods

A live Volume, returned by Volume::create() or VolumeBuilder::create(). Carries the backend it was created on.

vol.name()

The unique name identifying this volume.

Returns

&str
Volume name.

vol.kind()

The storage kind. See VolumeKind.

Returns

Storage kind.

vol.fs()

Get a filesystem handle for reading and writing the volume’s files directly, without a running sandbox. Local volumes route to tokio::fs; Cloud volumes route through the authenticated volume API. See VolumeFs for the operations.

Returns

Filesystem handle.

vol.path()

The host-side directory where this volume’s data is stored.

Returns

&Path
Host data directory, e.g. ~/.microsandbox/volumes/pip-cache/.

vol.disk_path()

Host path to the managed raw disk image (disk.raw) for disk volumes. Returns None for directory volumes.

Returns

Option<PathBuf>
Path to disk.raw, or None for directory volumes.

vol.capacity_bytes()

Disk capacity in bytes for disk volumes. None for directory volumes.

Returns

Option<u64>
Capacity in bytes, or None.

vol.disk_format()

Disk image format for disk volumes (always "raw" for managed disk volumes). None for directory volumes.

Returns

Option<&str>
Format string, or None.

vol.disk_fstype()

Inner disk filesystem type for disk volumes (always "ext4" for managed disk volumes). None for directory volumes.

Returns

Option<&str>
Filesystem type, or None.

vol.context_kind()

Which backend variant this volume is bound to: Local or Remote.

Returns

ContextKind
Local or Remote.

vol.local_state()

Returns Some for local-backed volumes and None otherwise.

Returns

Option<&VolumeLocalState>
Local state, or None.

vol.remote_state()

Returns Some for cloud-backed volumes and None otherwise.

Returns

Option<&VolumeRemoteState>
Cloud state, or None.

vol.destroy()

Delete this volume and its contents using its captured identity and context. A replacement with the same name is left untouched. Local removal retains its database record until filesystem cleanup succeeds, so interrupted cleanup can be retried.

vol.used_bytes()

Fetch fresh provider-reported disk usage. None means the provider has no measurement.

Returns

u64
Current reported usage, when available.

vol.info()

Fetch mutable metadata together for the captured identity. Each call reads the backend and returns lookup errors rather than captured data. Quota, usage, capacity, and label convenience methods are also asynchronous. Use info() to avoid observations from separate moments.

vol.quota_mib()

Maximum storage in MiB, or None if unlimited.

Returns

Option<u32>
Quota in MiB, or None.

vol.labels()

Key-value labels for organizing and filtering volumes.

Returns

&[(String, String)]
Label pairs.

vol.created_at()

When this volume was first created, if recorded.

Returns

Option<DateTime<Utc>>
Creation timestamp, or None.

VolumeFs

Local operations remain confined to the opened volume directory, including symlink traversal, missing parents, streams, copy, rename, and recursive deletion. Paths that leave the volume return an error. A leading / denotes the volume root; valid in-volume parent components and symlinks keep their meaning. Removing or renaming the volume root is refused.

Returned by Volume::fs()

Host-side filesystem operations for a named volume.

fs.read()

Read an entire file into memory as raw bytes.

Parameters

path&str
File path relative to the volume root.

Returns

Bytes
File contents.

fs.read_to_string()

Read an entire file into memory as a UTF-8 string.

Parameters

path&str
File path relative to the volume root.

Returns

String
File contents as UTF-8.

fs.read_stream()

Open a file for streaming reads. Returns a VolumeFsReadStream that yields 64 KiB chunks, so large files don’t have to be held in memory at once.

Parameters

path&str
File path relative to the volume root.

Returns

Chunked reader.

fs.write()

Write data to a file, creating parent directories as needed. Overwrites if the file already exists.

Parameters

path&str
File path relative to the volume root.
dataimpl AsRef<[u8]>
Bytes to write.

fs.write_stream()

Open a file for streaming writes. Returns a VolumeFsWriteSink that accepts chunks of bytes. Creates parent directories as needed.

Parameters

path&str
File path relative to the volume root.

Returns

Chunked writer.

fs.list()

List the immediate children of a directory (non-recursive). Each entry includes the path, kind, size, permissions, and modification time.

Parameters

path&str
Directory path relative to the volume root.

Returns

Directory entries.

fs.mkdir()

Create a directory and any missing parents.

Parameters

path&str
Directory path relative to the volume root.

fs.remove()

Delete a single file. Use remove_dir() for directories.

Parameters

path&str
File path relative to the volume root.

fs.remove_dir()

Remove a directory and its contents recursively. Targeting the volume root is rejected.

Parameters

path&str
Directory path relative to the volume root.

fs.copy()

Copy a file within the volume. Creates the destination’s parent directories as needed.

Parameters

from&str
Source path relative to the volume root.
to&str
Destination path relative to the volume root.

fs.rename()

Rename or move a file or directory. Creates the destination’s parent directories as needed.

Parameters

from&str
Source path relative to the volume root.
to&str
Destination path relative to the volume root.

fs.stat()

Get metadata for a file or directory: kind, size, permission bits, read-only flag, and timestamps.

Parameters

path&str
Path relative to the volume root.

Returns

Entry metadata.

fs.exists()

Check whether a file or directory exists at the given path. Returns false rather than an error if the path is absent.

Parameters

path&str
Path relative to the volume root.

Returns

bool
true if the path exists.

VolumeBuilder

Returned by Volume::builder()

Builder for configuring a named volume.

volume_builder.directory()

Create a directory-backed named volume (mounted through virtiofs). This is the default.

volume_builder.disk()

Create a raw ext4 disk-image named volume (mounted through virtio-blk). Requires .size().

volume_builder.size()

Set the disk volume’s capacity. Required for disk volumes; rejected for directory volumes. Accepts a bare u32 (MiB) or a SizeExt helper such as 20.gib().

Parameters

sizeimpl Into<Mebibytes>
Capacity in MiB.

volume_builder.quota()

Limit a directory volume’s storage. Accepts a bare 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>
Quota in MiB.

volume_builder.label()

Attach a key-value label for organizing and filtering volumes. Can be called multiple times.

Parameters

keyimpl Into<String>
Label key.
valueimpl Into<String>
Label value.

volume_builder.build()

Materialize the VolumeConfig without creating the volume. Pass the result to Volume::create() to provision it later.

Returns

The volume configuration.

volume_builder.create()

Create the volume on the active backend. Equivalent to Volume::create(self.build()).

Returns

The created volume.

MountBuilder

mount.owned()

Create an empty directory owned by this sandbox. It survives stop/start and is removed with the sandbox. Snapshots and forks capture it; restore makes private copies. Cloud rejects owned mounts.

mount.owned_with()

Configure an owned directory or raw ext4 disk. Directory storage accepts a quota; disks require a positive size. Common mount flags stay on MountBuilder. See owned mounts for lifecycle and examples.

mount.bind()

On our managed cloud, these paths refer to files in your organization’s host volume, rather than files on your computer.
Bind mount a host directory into the guest. Changes in the guest are reflected on the host and vice versa. The host path must be valid UTF-8 and must not contain ,, :, or ;.

Parameters

hostimpl Into<PathBuf>
Directory path on the host.

mount.named()

Mount a named volume created via 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>
Volume name.

mount.named_with()

Mount a named volume with explicit sandbox-time existence behavior, configured via a 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. With the cloud backend, ensure_exists supports default directory volumes without quota, capacity, or labels. The client looks up or creates the volume before creating the sandbox. Other inline creation settings are rejected. Locally, 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>
Volume name.
Configure existence behavior and creation metadata.

mount.tmpfs()

Use an in-memory filesystem. Contents are discarded when the sandbox stops. Good for scratch space, temp files, and build artifacts. Cap its size with .size().

mount.disk()

On our managed cloud, these paths refer to files in your organization’s host volume, rather than files on your computer.
Mount a host disk-image file as a virtio-blk device at the guest path. The format defaults from the file extension (.qcow2, .vmdk; anything else is Raw). Override with .format().

Parameters

hostimpl Into<PathBuf>
Disk image path on the host.

mount.format()

Override the disk-image format for a .disk() mount. Valid only with .disk(); calling it on a bind, named, or tmpfs mount errors when the SandboxBuilder is finalized.

Parameters

Disk image format.

mount.fstype()

Set the inner filesystem type for a .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>
Inner filesystem type.

mount.readonly()

Prevent writes to this mount. Enforced both at the host (virtiofs server rejects writes) and in the guest (the kernel returns EROFS).

mount.noexec()

Prevent direct execution of files on this mount. Interpreters can still read scripts from the mount, such as sh /mnt/script.sh, because the interpreter binary executes from a different filesystem.

mount.nosuid()

Ignore setuid and setgid privilege elevation from files on this mount.

mount.nodev()

Ignore device files on this mount.

mount.stat_virtualization()

Set the guest stat virtualization policy for a virtiofs-backed mount. Default: 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

Stat virtualization policy.

mount.host_permissions()

Set the host permission propagation policy for a virtiofs-backed mount. Default: 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

Host permission propagation policy.

mount.owner()

Present host files without a per-file stat override as the specified guest owner. Existing per-file overrides still take precedence, and the host inode is not changed. Valid only for bind and directory-backed named-volume mounts with stat virtualization enabled; tmpfs, disk images, disk-backed named volumes, and StatVirtualization::Off are rejected.

mount.size()

Set the size limit for a .tmpfs() mount. Accepts a bare u32 (MiB) or a SizeExt helper such as 1.gib(). Valid only for tmpfs mounts.

Parameters

sizeimpl Into<Mebibytes>
Size limit in MiB.

mount.build()

Validate and materialize the mount. Usually called internally by 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

VolumeMount
Validated mount specification.

NamedVolumeBuilder

Used by MountBuilder::named_with()

Sub-builder for MountBuilder::named_with(). Selects the sandbox-time existence behavior and, for create / ensure_exists, the creation metadata. Defaults to existing and directory-backed.

named.existing()

Require the named volume to already exist. This is the default.

named.create()

Create the named volume at sandbox launch and fail if it already exists.

named.ensure_exists()

Create the named volume if it is missing, or reuse a compatible existing volume. Errors if an existing volume’s kind, quota, capacity, or explicitly requested labels differ.

named.name()

Override the volume name passed to named_with().

Parameters

nameimpl Into<String>
Volume name.

named.directory()

Use directory-backed storage for a created volume. This is the default. Clears any previously set disk capacity.

named.disk()

Use raw ext4 disk-image storage for a created volume. Requires .size(). Clears any previously set quota.

named.size()

Set disk capacity for a created disk volume. Accepts a bare u32 (MiB) or a SizeExt helper.

Parameters

sizeimpl Into<Mebibytes>
Capacity in MiB.

named.quota()

Set a storage quota for a created directory volume. Accepts a bare u32 (MiB) or a SizeExt helper.

Parameters

sizeimpl Into<Mebibytes>
Quota in MiB.

named.label()

Attach a label to a newly-created volume. For ensure_exists, requested labels must match the existing volume. Can be called multiple times.

Parameters

keyimpl Into<String>
Label key.
valueimpl Into<String>
Label value.

VolumeFsReadStream

Returned by VolumeFs::read_stream()

A streaming reader for file data from a local volume directory.

stream.recv()

Next chunk; None at EOF

Returns

Option<Bytes>

stream.collect()

Read the rest into one buffer

Returns

Bytes

VolumeFsWriteSink

Returned by VolumeFs::write_stream()

A streaming writer for file data to a local volume directory.

sink.write()

Append a chunk

sink.close()

Flush and close

Types

VolumeKind

Storage kind for a named volume.

Returned by Volume::kind()

VolumeSpec

Configuration for creating a named volume. Re-exported as both VolumeSpec and the alias VolumeConfig.

Used by Volume::create() · returned by VolumeBuilder::build()

MountOptions

Guest mount behavior shared by every mount kind. Set via the MountBuilder toggles; all fields default to false.

StatVirtualization

Stat virtualization policy for a virtiofs-backed mount. Default: Strict. Set via MountBuilder::stat_virtualization().

HostPermissions

Host permission propagation policy for a virtiofs-backed mount. Default: Private. Set via MountBuilder::host_permissions().

DiskImageFormat

Disk image format for virtio-blk root filesystems and volume mounts. Used by MountBuilder::format().

NamedVolumeMode

Sandbox-time behavior for a named volume mount, chosen via NamedVolumeBuilder.

OwnedVolumeBuilder

owned.directory()

Select directory storage (the default).

owned.disk()

Select raw ext4 disk storage. Requires a positive size.

owned.quota()

Set a directory quota in MiB. Unset means no quota.

owned.size()

Set disk capacity in MiB. The value must be positive.