Back to Microsandbox

Volumes

docs/sdk/rust/volumes.mdx

0.6.956.5 KB
Original Source

Create, manage, and mount named volumes. See Volumes for usage examples.

Volume

<span className="msb-recv">Volume::</span><span className="msb-hn">get_default()</span>

rust
async fn get_default() -> MicrosandboxResult<VolumeHandle>

Get the Cloud account'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.

rust
let volume = Volume::get_default().await?;
volume.fs().write("customers/acme.json", br#"{"active":true}"#).await?;
println!("{}", volume.fs().read_to_string("customers/acme.json").await?);

<span className="msb-recv">Volume::</span><span className="msb-hn">builder()</span>

rust
fn builder(name: impl Into<String>) -> VolumeBuilder
<Accordion title="Example">
rust
let vol = Volume::builder("pip-cache").create().await?;
</Accordion>

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>name</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Volume name, e.g. <code>"pip-cache"</code>.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumebuilder-2">VolumeBuilder</a></div> <div className="msb-param-desc">Builder for configuring the volume.</div> </div> </div>

<span className="msb-recv">Volume::</span><span className="msb-hn">create()</span>

rust
async fn create(config: VolumeConfig) -> MicrosandboxResult<Volume>
<Accordion title="Example">
rust
use microsandbox::volume::{VolumeConfig, VolumeKind};

let vol = Volume::create(VolumeConfig {
    name: "cache".into(),
    kind: VolumeKind::Directory,
    quota_mib: Some(1024),
    capacity_mib: None,
    labels: vec![("team".into(), "ml".into())],
})
.await?;
</Accordion>

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>config</code><a className="msb-type" href="#volumespec">VolumeConfig</a></div> <div className="msb-param-desc">Volume configuration. <code>VolumeConfig</code> is an alias for <a className="msb-type" href="#volumespec">VolumeSpec</a>.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volume">Volume</a></div> <div className="msb-param-desc">The created volume.</div> </div> </div>

<span className="msb-recv">Volume::</span><span className="msb-hn">get()</span>

rust
async fn get(name: &str) -> MicrosandboxResult<VolumeHandle>
<Accordion title="Example">
rust
let h = Volume::get("pip-cache").await?;
println!("{} - {} bytes used", h.name(), h.used_bytes());
</Accordion>

Get a handle to an existing named volume. Use the handle 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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>name</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Volume name.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumehandle">VolumeHandle</a></div> <div className="msb-param-desc">Handle for host-side operations.</div> </div> </div>

<span className="msb-recv">Volume::</span><span className="msb-hn">list()</span>

rust
async fn list() -> MicrosandboxResult<Vec<VolumeHandle>>
<Accordion title="Example">
rust
for h in Volume::list().await? {
    println!("{} - {:?}", h.name(), h.kind());
}
</Accordion>

List all named volumes, newest first.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumehandle">Vec&lt;VolumeHandle&gt;</a></div> <div className="msb-param-desc">All volume handles.</div> </div> </div>

<span className="msb-recv">Volume::</span><span className="msb-hn">remove()</span>

rust
async fn remove(name: &str) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
Volume::remove("pip-cache").await?;
</Accordion>

Delete a named volume and its contents from disk. Locally the database record is deleted first, then the directory, so an orphaned directory is easier to detect than an orphaned record. Fails with VolumeNotFound if the volume does not exist.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>name</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Volume name.</div> </div> </div> <p className="msb-member-group">Instance methods</p>

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

<span className="msb-recv">vol.</span><span className="msb-hn">name()</span>

rust
fn name(&self) -> &str

The unique name identifying this volume.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Volume name.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">kind()</span>

rust
fn kind(&self) -> VolumeKind

The storage kind: Directory or Disk.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumekind">VolumeKind</a></div> <div className="msb-param-desc">Storage kind.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">fs()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn fs(&self) -> VolumeFs<'_>
<Accordion title="Example">
rust
vol.fs().write("/seed.txt", "hello").await?;
</Accordion>

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.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumefs">VolumeFs</a></div> <div className="msb-param-desc">Filesystem handle.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">path()</span>

rust
fn path(&self) -> MicrosandboxResult<&Path>
<Accordion title="Example">
rust
println!("{}", vol.path()?.display());
</Accordion>

The host-side directory where this volume's data is stored (local backend only). Errors with Unsupported for cloud volumes, whose bytes live in the org's object storage rather than on the caller's host.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">&amp;Path</span></div> <div className="msb-param-desc">Host data directory, e.g. <code>~/.microsandbox/volumes/pip-cache/</code>.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">disk_path()</span>

rust
fn disk_path(&self) -> Option<PathBuf>

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;PathBuf&gt;</span></div> <div className="msb-param-desc">Path to <code>disk.raw</code>, or <code>None</code> for directory volumes.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">capacity_bytes()</span>

rust
fn capacity_bytes(&self) -> Option<u64>

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;u64&gt;</span></div> <div className="msb-param-desc">Capacity in bytes, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">disk_format()</span>

rust
fn disk_format(&self) -> Option<&str>

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;str&gt;</span></div> <div className="msb-param-desc">Format string, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">disk_fstype()</span>

rust
fn disk_fstype(&self) -> Option<&str>

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;str&gt;</span></div> <div className="msb-param-desc">Filesystem type, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">backend_kind()</span>

rust
fn backend_kind(&self) -> BackendKind

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">BackendKind</span></div> <div className="msb-param-desc"><code>Local</code> or <code>Cloud</code>.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">local()</span>

rust
fn local(&self) -> Option<&VolumeLocalState>

Local-only volume state. Returns Some for local-backed volumes, None for cloud-backed ones.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;VolumeLocalState&gt;</span></div> <div className="msb-param-desc">Local state, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">vol.</span><span className="msb-hn">cloud()</span>

<Tooltip tip="Returns state only for cloud-backed volumes; None on the local backend."><span className="msb-badge-cloud">Cloud-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn cloud(&self) -> Option<&VolumeCloudState>

Cloud-only volume state. Returns Some for cloud-backed volumes, None for local-backed ones.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;VolumeCloudState&gt;</span></div> <div className="msb-param-desc">Cloud state, or <code>None</code>.</div> </div> </div>

VolumeHandle

<p className="msb-backref">Returned by <a href="#volumeget">Volume::get()</a> · <a href="#volumelist">Volume::list()</a></p>

A metadata and lifecycle handle for a named volume.

<span className="msb-recv">h.</span><span className="msb-hn">name()</span>

rust
fn name(&self) -> &str

The unique name identifying this volume.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Volume name.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">kind()</span>

rust
fn kind(&self) -> VolumeKind

The storage kind: Directory or Disk.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumekind">VolumeKind</a></div> <div className="msb-param-desc">Storage kind.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">fs()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn fs(&self) -> VolumeFs<'_>
<Accordion title="Example">
rust
let h = Volume::get("pip-cache").await?;
let names = h.fs().list("/").await?;
</Accordion>

Get a filesystem handle for reading and writing the volume's files directly, without a running sandbox. See VolumeFs.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumefs">VolumeFs</a></div> <div className="msb-param-desc">Filesystem handle.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">remove()</span>

rust
async fn remove(&self) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
Volume::get("pip-cache").await?.remove().await?;
</Accordion>

Delete this volume and its contents. Locally the database record is removed first, then the directory.

<span className="msb-recv">h.</span><span className="msb-hn">used_bytes()</span>

rust
fn used_bytes(&self) -> u64

Disk usage snapshot from when this handle was created. Not live, call Volume::get() again for a fresh reading.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">u64</span></div> <div className="msb-param-desc">Bytes used at handle-creation time.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">quota_mib()</span>

rust
fn quota_mib(&self) -> Option<u32>

Maximum storage in MiB, or None if unlimited.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;u32&gt;</span></div> <div className="msb-param-desc">Quota in MiB, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">capacity_bytes()</span>

rust
fn capacity_bytes(&self) -> Option<u64>

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;u64&gt;</span></div> <div className="msb-param-desc">Capacity in bytes, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">disk_format()</span>

rust
fn disk_format(&self) -> Option<&str>

Disk image format for disk volumes. None for directory volumes.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;str&gt;</span></div> <div className="msb-param-desc">Format string, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">disk_fstype()</span>

rust
fn disk_fstype(&self) -> Option<&str>

Inner disk filesystem type for disk volumes. None for directory volumes.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;str&gt;</span></div> <div className="msb-param-desc">Filesystem type, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">disk_path()</span>

rust
fn disk_path(&self) -> Option<PathBuf>

Host path to the managed raw disk image (disk.raw) for local disk volumes. None otherwise.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;PathBuf&gt;</span></div> <div className="msb-param-desc">Path to <code>disk.raw</code>, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">labels()</span>

rust
fn labels(&self) -> &[(String, String)]

Key-value labels for organizing and filtering volumes.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">&amp;[(String, String)]</span></div> <div className="msb-param-desc">Label pairs.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">created_at()</span>

rust
fn created_at(&self) -> Option<DateTime<Utc>>

When this volume was first created, if recorded.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;DateTime&lt;Utc&gt;&gt;</span></div> <div className="msb-param-desc">Creation timestamp, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">backend_kind()</span>

rust
fn backend_kind(&self) -> BackendKind

Which backend variant this handle is bound to: Local or Cloud.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">BackendKind</span></div> <div className="msb-param-desc"><code>Local</code> or <code>Cloud</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">local()</span>

rust
fn local(&self) -> Option<&VolumeHandleLocalState>

Local-only handle state. Returns Some for local-backed handles, None for cloud-backed ones.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;VolumeHandleLocalState&gt;</span></div> <div className="msb-param-desc">Local state, or <code>None</code>.</div> </div> </div>

<span className="msb-recv">h.</span><span className="msb-hn">cloud()</span>

<Tooltip tip="Returns state only for cloud-backed volume handles; None on the local backend."><span className="msb-badge-cloud">Cloud-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn cloud(&self) -> Option<&VolumeHandleCloudState>

Cloud-only handle state. Returns Some for cloud-backed handles, None for local-backed ones.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Option&lt;&amp;VolumeHandleCloudState&gt;</span></div> <div className="msb-param-desc">Cloud state, or <code>None</code>.</div> </div> </div>

VolumeFs

<p className="msb-backref">Returned by <a href="#vol-fs">Volume::fs()</a> · <a href="#h-fs">VolumeHandle::fs()</a></p>

Host-side filesystem operations for a named volume.

<span className="msb-recv">fs.</span><span className="msb-hn">read()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
async fn read(&self, path: &str) -> MicrosandboxResult<Bytes>
<Accordion title="Example">
rust
let data = vol.fs().read("/seed.txt").await?;
</Accordion>

Read an entire file into memory as raw bytes.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">File path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">Bytes</span></div> <div className="msb-param-desc">File contents.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">read_to_string()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
async fn read_to_string(&self, path: &str) -> MicrosandboxResult<String>
<Accordion title="Example">
rust
let text = vol.fs().read_to_string("/seed.txt").await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">File path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">String</span></div> <div className="msb-param-desc">File contents as UTF-8.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">read_stream()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
async fn read_stream(&self, path: &str) -> MicrosandboxResult<VolumeFsReadStream>
<Accordion title="Example">
rust
let mut stream = vol.fs().read_stream("/model.bin").await?;
while let Some(chunk) = stream.recv().await? {
    // process chunk
}
</Accordion>

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">File path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumefsreadstream">VolumeFsReadStream</a></div> <div className="msb-param-desc">Chunked reader.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">write()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
async fn write(&self, path: &str, data: impl AsRef<[u8]>) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
vol.fs().write("/config/app.json", r#"{"ready":true}"#).await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">File path relative to the volume root.</div> </div> <div className="msb-param"> <div className="msb-param-key"><code>data</code><span className="msb-type">impl AsRef&lt;[u8]&gt;</span></div> <div className="msb-param-desc">Bytes to write.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">write_stream()</span>

<Tooltip tip="Unmounted-volume filesystem access is not available on microsandbox cloud; mount the volume into a sandbox and use the sandbox filesystem."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
async fn write_stream(&self, path: &str) -> MicrosandboxResult<VolumeFsWriteSink>
<Accordion title="Example">
rust
let mut sink = vol.fs().write_stream("/upload.bin").await?;
sink.write(&chunk).await?;
sink.close().await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">File path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumefswritesink">VolumeFsWriteSink</a></div> <div className="msb-param-desc">Chunked writer.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">list()</span>

rust
async fn list(&self, path: &str) -> MicrosandboxResult<Vec<FsEntry>>
<Accordion title="Example">
rust
for entry in vol.fs().list("/").await? {
    println!("{} ({} bytes)", entry.path, entry.size);
}
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Directory path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="/sdk/rust/filesystem#fsentry">Vec&lt;FsEntry&gt;</a></div> <div className="msb-param-desc">Directory entries.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">mkdir()</span>

rust
async fn mkdir(&self, path: &str) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
vol.fs().mkdir("/data/incoming").await?;
</Accordion>

Create a directory and any missing parents.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Directory path relative to the volume root.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">remove()</span>

rust
async fn remove(&self, path: &str) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
vol.fs().remove("/data/stale.tmp").await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">File path relative to the volume root.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">remove_dir()</span>

rust
async fn remove_dir(&self, path: &str) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
vol.fs().remove_dir("/data/incoming").await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Directory path relative to the volume root.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">copy()</span>

rust
async fn copy(&self, from: &str, to: &str) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
vol.fs().copy("/seed.txt", "/backup/seed.txt").await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>from</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Source path relative to the volume root.</div> </div> <div className="msb-param"> <div className="msb-param-key"><code>to</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Destination path relative to the volume root.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">rename()</span>

rust
async fn rename(&self, from: &str, to: &str) -> MicrosandboxResult<()>
<Accordion title="Example">
rust
vol.fs().rename("/tmp/out.txt", "/done/out.txt").await?;
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>from</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Source path relative to the volume root.</div> </div> <div className="msb-param"> <div className="msb-param-key"><code>to</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Destination path relative to the volume root.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">stat()</span>

rust
async fn stat(&self, path: &str) -> MicrosandboxResult<FsMetadata>
<Accordion title="Example">
rust
let meta = vol.fs().stat("/seed.txt").await?;
println!("{} bytes", meta.size);
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="/sdk/rust/filesystem#fsmetadata">FsMetadata</a></div> <div className="msb-param-desc">Entry metadata.</div> </div> </div>

<span className="msb-recv">fs.</span><span className="msb-hn">exists()</span>

rust
async fn exists(&self, path: &str) -> MicrosandboxResult<bool>
<Accordion title="Example">
rust
if !vol.fs().exists("/seed.txt").await? {
    vol.fs().write("/seed.txt", "hello").await?;
}
</Accordion>

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>path</code><span className="msb-type">&amp;str</span></div> <div className="msb-param-desc">Path relative to the volume root.</div> </div> </div> <p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">bool</span></div> <div className="msb-param-desc"><code>true</code> if the path exists.</div> </div> </div>

VolumeBuilder

<p className="msb-backref">Returned by <a href="#volumebuilder">Volume::builder()</a></p>

Builder for configuring a named volume.

<span className="msb-recv">volume_builder.</span><span className="msb-hn">directory()</span>

rust
fn directory(self) -> Self

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

<span className="msb-recv">volume_builder.</span><span className="msb-hn">disk()</span>

<Tooltip tip="Disk-kind volumes are not available on microsandbox cloud; use a directory-backed named volume."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn disk(self) -> Self

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

<span className="msb-recv">volume_builder.</span><span className="msb-hn">size()</span>

<Tooltip tip="Disk-kind volumes are not available on microsandbox cloud; use a directory-backed named volume."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn size(self, size: impl Into<Mebibytes>) -> Self
<Accordion title="Example">
rust
use microsandbox::size::SizeExt;

let vol = Volume::builder("docker-data")
    .disk()
    .size(20.gib())
    .create()
    .await?;
</Accordion>

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().

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>size</code><span className="msb-type">impl Into&lt;Mebibytes&gt;</span></div> <div className="msb-param-desc">Capacity in MiB.</div> </div> </div>

<span className="msb-recv">volume_builder.</span><span className="msb-hn">quota()</span>

<Tooltip tip="On microsandbox cloud, quota sets a storage cap and must be a whole number of GiB."><span className="msb-badge-note">On cloud <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn quota(self, size: impl Into<Mebibytes>) -> Self

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().

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>size</code><span className="msb-type">impl Into&lt;Mebibytes&gt;</span></div> <div className="msb-param-desc">Quota in MiB.</div> </div> </div>

<span className="msb-recv">volume_builder.</span><span className="msb-hn">label()</span>

rust
fn label(self, key: impl Into<String>, value: impl Into<String>) -> Self

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>key</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Label key.</div> </div> <div className="msb-param"> <div className="msb-param-key"><code>value</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Label value.</div> </div> </div>

<span className="msb-recv">volume_builder.</span><span className="msb-hn">build()</span>

<a id="vb-build"></a>

rust
fn build(self) -> VolumeConfig

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volumespec">VolumeConfig</a></div> <div className="msb-param-desc">The volume configuration.</div> </div> </div>

<span className="msb-recv">volume_builder.</span><span className="msb-hn">create()</span>

<a id="vb-create"></a>

rust
async fn create(self) -> MicrosandboxResult<Volume>
<Accordion title="Example">
rust
let vol = Volume::builder("pip-cache")
    .quota(1024)
    .label("team", "ml")
    .create()
    .await?;
</Accordion>

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

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><a className="msb-type" href="#volume">Volume</a></div> <div className="msb-param-desc">The created volume.</div> </div> </div>

MountBuilder

<p className="msb-backref">Used by <a href="/sdk/rust/sandbox#volume">SandboxBuilder::volume()</a></p>

Builder for configuring a sandbox volume mount.

<span className="msb-recv">mount.</span><span className="msb-hn">bind()</span>

rust
fn bind(self, host: impl Into<PathBuf>) -> Self

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 ;.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>host</code><span className="msb-type">impl Into&lt;PathBuf&gt;</span></div> <div className="msb-param-desc">Directory path on the host.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">named()</span>

rust
fn named(self, name: impl Into<String>) -> Self

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().

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>name</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Volume name.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">named_with()</span>

<Tooltip tip="On microsandbox cloud, create the named volume before mounting; create-on-mount, disk-kind, and size are not available."><span className="msb-badge-limited">Limited on cloud <Icon icon="circle-info" size={11} /></span></Tooltip>

rust
fn named_with(
    self,
    name: impl Into<String>,
    f: impl FnOnce(NamedVolumeBuilder) -> NamedVolumeBuilder,
) -> Self
<Accordion title="Example">
rust
use microsandbox::size::SizeExt;

let sb = Sandbox::builder("worker")
    .image("python")
    .volume("/cache", |v| v.named_with("pip-cache", |n| n.ensure_exists()))
    .volume("/var/lib/docker", |v| {
        v.named_with("docker-data", |n| n.ensure_exists().disk().size(20.gib()))
    })
    .create()
    .await?;
</Accordion>

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. 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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>name</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Volume name.</div> </div> <div className="msb-param"> <div className="msb-param-key"><code>f</code><a className="msb-type" href="#namedvolumebuilder-2">FnOnce(NamedVolumeBuilder)</a></div> <div className="msb-param-desc">Configure existence behavior and creation metadata.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">tmpfs()</span>

rust
fn tmpfs(self) -> Self

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().

<span className="msb-recv">mount.</span><span className="msb-hn">disk()</span>

<Tooltip tip="On microsandbox cloud, the disk-image path resolves against your organization's host volume, not the computer running the SDK or CLI."><span className="msb-badge-note">On cloud <Icon icon="circle-info" size={11} /></span></Tooltip>

<a id="mb-disk"></a>

rust
fn disk(self, host: impl Into<PathBuf>) -> Self

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().

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>host</code><span className="msb-type">impl Into&lt;PathBuf&gt;</span></div> <div className="msb-param-desc">Disk image path on the host.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">format()</span>

rust
fn format(self, format: DiskImageFormat) -> Self

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>format</code><a className="msb-type" href="#diskimageformat">DiskImageFormat</a></div> <div className="msb-param-desc">Disk image format.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">fstype()</span>

rust
fn fstype(self, fstype: impl Into<String>) -> Self

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().

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>fstype</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Inner filesystem type.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">readonly()</span>

rust
fn readonly(self) -> Self

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

<span className="msb-recv">mount.</span><span className="msb-hn">noexec()</span>

rust
fn noexec(self) -> Self

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.

<span className="msb-recv">mount.</span><span className="msb-hn">nosuid()</span>

rust
fn nosuid(self) -> Self

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

<span className="msb-recv">mount.</span><span className="msb-hn">nodev()</span>

rust
fn nodev(self) -> Self

Ignore device files on this mount.

<span className="msb-recv">mount.</span><span className="msb-hn">stat_virtualization()</span>

rust
fn stat_virtualization(self, policy: StatVirtualization) -> Self

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>policy</code><a className="msb-type" href="#statvirtualization">StatVirtualization</a></div> <div className="msb-param-desc">Stat virtualization policy.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">host_permissions()</span>

rust
fn host_permissions(self, policy: HostPermissions) -> Self

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>policy</code><a className="msb-type" href="#hostpermissions">HostPermissions</a></div> <div className="msb-param-desc">Host permission propagation policy.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">size()</span>

<a id="mb-size"></a>

rust
fn size(self, size: impl Into<Mebibytes>) -> Self

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.

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>size</code><span className="msb-type">impl Into&lt;Mebibytes&gt;</span></div> <div className="msb-param-desc">Size limit in MiB.</div> </div> </div>

<span className="msb-recv">mount.</span><span className="msb-hn">build()</span>

<a id="mb-build"></a>

rust
fn build(self) -> MicrosandboxResult<VolumeMount>

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.

<p className="msb-label">Returns</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><span className="msb-type">VolumeMount</span></div> <div className="msb-param-desc">Validated mount specification.</div> </div> </div>

NamedVolumeBuilder

Sub-builder for MountBuilder::named_with(). Selects sandbox-time existence behavior and creation metadata.

<p className="msb-backref">Used by <a href="#named_with">MountBuilder::named_with()</a></p>

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.

<span className="msb-recv">named.</span><span className="msb-hn">existing()</span>

<a id="nv-existing"></a>

rust
fn existing(self) -> Self

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

<span className="msb-recv">named.</span><span className="msb-hn">create()</span>

<a id="nv-create"></a>

rust
fn create(self) -> Self

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

<span className="msb-recv">named.</span><span className="msb-hn">ensure_exists()</span>

<a id="nv-ensure_exists"></a>

rust
fn ensure_exists(self) -> Self

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.

<span className="msb-recv">named.</span><span className="msb-hn">name()</span>

<a id="nv-name"></a>

rust
fn name(self, name: impl Into<String>) -> Self

Override the volume name passed to named_with().

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>name</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Volume name.</div> </div> </div>

<span className="msb-recv">named.</span><span className="msb-hn">directory()</span>

<a id="nv-directory"></a>

rust
fn directory(self) -> Self

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

<span className="msb-recv">named.</span><span className="msb-hn">disk()</span>

<Tooltip tip="Disk-kind volumes are not available on microsandbox cloud; use a directory-backed named volume."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

<a id="nv-disk"></a>

rust
fn disk(self) -> Self

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

<span className="msb-recv">named.</span><span className="msb-hn">size()</span>

<Tooltip tip="Disk-kind volumes are not available on microsandbox cloud; use a directory-backed named volume."><span className="msb-badge-local">Local-only <Icon icon="circle-info" size={11} /></span></Tooltip>

<a id="nv-size"></a>

rust
fn size(self, size: impl Into<Mebibytes>) -> Self

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>size</code><span className="msb-type">impl Into&lt;Mebibytes&gt;</span></div> <div className="msb-param-desc">Capacity in MiB.</div> </div> </div>

<span className="msb-recv">named.</span><span className="msb-hn">quota()</span>

<Tooltip tip="On microsandbox cloud, quota sets a storage cap and must be a whole number of GiB."><span className="msb-badge-note">On cloud <Icon icon="circle-info" size={11} /></span></Tooltip>

<a id="nv-quota"></a>

rust
fn quota(self, size: impl Into<Mebibytes>) -> Self

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>size</code><span className="msb-type">impl Into&lt;Mebibytes&gt;</span></div> <div className="msb-param-desc">Quota in MiB.</div> </div> </div>

<span className="msb-recv">named.</span><span className="msb-hn">label()</span>

<a id="nv-label"></a>

rust
fn label(self, key: impl Into<String>, value: impl Into<String>) -> Self

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

<p className="msb-label">Parameters</p> <div className="msb-params"> <div className="msb-param"> <div className="msb-param-key"><code>key</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Label key.</div> </div> <div className="msb-param"> <div className="msb-param-key"><code>value</code><span className="msb-type">impl Into&lt;String&gt;</span></div> <div className="msb-param-desc">Label value.</div> </div> </div>

VolumeFsReadStream

A streaming reader for file data from a local volume directory. Returned by VolumeFs::read_stream().

<p className="msb-backref">Returned by <a href="#fs-read_stream">VolumeFs::read_stream()</a></p>

<span className="msb-recv">stream.</span><span className="msb-hn">recv()</span>

rust
recv()

Next chunk; None at EOF

<p className="msb-label">Returns</p>

Option<Bytes>

<span className="msb-recv">stream.</span><span className="msb-hn">collect()</span>

rust
collect()

Read the rest into one buffer

<p className="msb-label">Returns</p>

Bytes

VolumeFsWriteSink

A streaming writer for file data to a local volume directory. Returned by VolumeFs::write_stream().

<p className="msb-backref">Returned by <a href="#fs-write_stream">VolumeFs::write_stream()</a></p>

<span className="msb-recv">sink.</span><span className="msb-hn">write()</span>

rust
write(data)

Append a chunk

<span className="msb-recv">sink.</span><span className="msb-hn">close()</span>

rust
close()

Flush and close

Types

VolumeKind

Storage kind for a named volume.

<p className="msb-backref">Returned by <a href="#vol-kind">Volume::kind()</a> · <a href="#h-kind">VolumeHandle::kind()</a></p>
VariantDescription
DirectoryDirectory-backed volume mounted through virtiofs
DiskRaw ext4 disk-image volume mounted through virtio-blk

VolumeSpec

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

<p className="msb-backref">Used by <a href="#volumecreate">Volume::create()</a> · returned by <a href="#vb-build">VolumeBuilder::build()</a></p>
FieldTypeDescription
nameStringVolume name
kindVolumeKindStorage kind
quota_mibOption<u32>Size quota in MiB; None is unlimited
capacity_mibOption<u32>Disk capacity in MiB; required for disk volumes
labelsVec<(String, String)>Organization labels

MountOptions

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

FieldTypeDescription
readonlyboolGuest writes fail; virtiofs mounts also reject host-side writes
noexecboolDirect execution from the mount is disabled
nosuidboolsetuid/setgid elevation from files on the mount is ignored
nodevboolDevice files on the mount are ignored

StatVirtualization

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

VariantDescription
StrictFail-closed: probe the host backing path; require xattr support
RelaxedOpportunistic: apply the overlay when present; tolerate missing xattr support
OffLiteral 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().

VariantDescription
PrivateGuest chmod stays in the metadata overlay only
MirrorMirror ordinary rwx bits for files and directories to the host inode

DiskImageFormat

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

VariantDescription
Qcow2QEMU Copy-on-Write v2
RawRaw disk image
VmdkVMware Disk (FLAT/ZERO only, no delta links)

NamedVolumeMode

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

VariantDescription
ExistingRequire the named volume to already exist (default)
CreateCreate the named volume and fail if it already exists
EnsureExistsEnsure the volume exists, or reuse a compatible existing one