Skip to main content
Volumes give the guest direct filesystem access to host-side directories, which is much faster than the filesystem API since that transfers files individually. The guest handles caching and readahead natively, so performance is close to native disk I/O. See Volume concepts for more on bind mounts, named volumes, and tmpfs.

Create a named volume

Named volumes are managed by microsandbox and stored at ~/.microsandbox/volumes/<name>/. You can set a storage quota at creation time.
use microsandbox::Volume;

let cache = Volume::builder("pip-cache")
    .quota(1024)
    .create()
    .await?;

Mount volumes

Three mount types: bind mounts (host directory), named volumes (managed storage), and tmpfs (in-memory, ephemeral).
use microsandbox::{Sandbox, Volume};

let cache = Volume::builder("pip-cache")
    .quota(1024)
    .create()
    .await?;

let sb = Sandbox::builder("worker")
    .image("python:3.12")
    .volume("/app/src", |v| v.bind("./src").readonly())
    .volume("/root/.cache/pip", |v| v.named(cache.name()))
    .volume("/tmp/scratch", |v| v.tmpfs().size(100))
    .create()
    .await?;

Host-side file access

Read and write files in a named volume from the host without a running sandbox. Useful for pre-populating data before creating a sandbox.
use microsandbox::Volume;

let vol = Volume::get("pip-cache").await?;
vol.fs().write("/requirements.txt", "requests==2.28.0").await?;
let content = vol.fs().read_to_string("/requirements.txt").await?;

List and remove volumes

use microsandbox::Volume;

let volumes = Volume::list().await?;
Volume::remove("old-cache").await?;