Skip to main content
Create, manage, and mount named volumes. See Volumes for usage examples.

Volume

Instance properties

volume.name

Volume name.

volume.path

Host path to the volume’s directory.

Static methods

Volume.get_default()

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 raises a typed unsupported error; it never substitutes a directory from the caller’s machine.

Volume.create()

Create a new named volume. VolumeKind.DIRECTORY creates a host directory; VolumeKind.DISK creates a backing disk image and requires size_mib.

Parameters

namestr
Volume name.
Volume kind. Defaults to DIRECTORY.
size_mibint | None
Disk capacity in MiB; required with kind=VolumeKind.DISK.
quota_mibint | None
Quota in MiB recorded for directory volumes.
labelsdict[str, str] | None
Metadata labels.

Returns

Created volume, exposing name and path.

Volume.get()

Get a lightweight handle to an existing named volume, with its metadata and a direct filesystem handle.

Parameters

namestr
Volume name.

Returns

Handle with metadata and a filesystem accessor.

Volume.list()

List all named volumes.

Returns

All volume handles.

Volume.remove()

Delete a named volume and its contents. Fails if the volume is currently mounted.

Parameters

namestr
Volume name.

Mount factories

Static factory methods on Volume 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()

Mount a host directory into the sandbox. Changes in the guest are reflected on the host and vice versa.

Parameters

pathstr
Directory path on the host.
readonlybool
Mount as read-only; virtiofs-backed mounts also reject writes in the host filesystem server.
noexecbool
Prevent direct execution from the mount.
nosuidbool
Ignore setuid and setgid privilege elevation from files on the mount.
nodevbool
Ignore device files on the mount.
stat_virtualizationStatVirtualization | None
Guest stat-virtualization policy.
host_permissionsHostPermissions | None
Host permission propagation policy.
uidint | None
Guest uid fallback for host files without a per-file stat override; set together with gid.
gidint | None
Guest gid fallback for host files without a per-file stat override; set together with uid.

Returns

Mount configuration.

Volume.named()

Mount a named volume. By default the volume must already exist; set mode to control creation behavior and use kind, size_mib, and quota_mib when creating it.

Parameters

namestr
Volume name.
Whether to require, create, or ensure the named volume.
Storage kind when the mount may create the volume.
size_mibint | None
Disk capacity when creating a disk volume.
quota_mibint | None
Quota when creating a directory volume.
readonlybool
Mount as read-only; virtiofs-backed mounts also reject writes in the host filesystem server.
noexecbool
Prevent direct execution from the mount.
nosuidbool
Ignore setuid and setgid privilege elevation from files on the mount.
nodevbool
Ignore device files on the mount.
stat_virtualizationStatVirtualization | None
Guest stat-virtualization policy for a directory-backed volume.
host_permissionsHostPermissions | None
Host permission propagation policy for a directory-backed volume.
uidint | None
Guest uid fallback; set together with gid and use only with directory-backed volumes.
gidint | None
Guest gid fallback; set together with uid and use only with directory-backed volumes.

Returns

Mount configuration.

Volume.tmpfs()

Use an in-memory filesystem. Contents are discarded when the sandbox stops.

Parameters

size_mibint | None
Maximum size in MiB.
readonlybool
Mount as read-only.
noexecbool
Prevent direct execution from the mount.
nosuidbool
Ignore setuid and setgid privilege elevation from files on the mount.
nodevbool
Ignore device files on the mount.

Returns

Mount configuration.

Volume.disk()

Mount a host disk image as a virtio-blk device. 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

pathstr
Host path to the disk image.
Disk image format hint. See DiskImageFormat.
fstypestr | None
Inner filesystem type.
readonlybool
Mount as read-only.
noexecbool
Prevent direct execution from the mount.
nosuidbool
Ignore setuid and setgid privilege elevation from files on the mount.
nodevbool
Ignore device files on the mount.

Returns

Mount configuration.

VolumeHandle

Returned by Volume.get(), Volume.list()

A lightweight handle to a named volume, with its database metadata and a host-side filesystem accessor.

handle.name

str Volume name

handle.kind

VolumeKind Volume storage kind

handle.quota_mib

int \| None Storage quota in MiB

handle.used_bytes

int Current disk usage in bytes

handle.capacity_bytes

int \| None Disk capacity in bytes

handle.disk_format

DiskImageFormat \| None Disk image format

handle.disk_fstype

str \| None Disk filesystem type

handle.labels

dict[str, str] Metadata labels

handle.created_at

float \| None Creation timestamp (ms since epoch)

handle.fs

VolumeFs Host-side filesystem handle

handle.remove()

Delete this volume

Returns

(async) None

VolumeFs

Returned by VolumeHandle.fs

Host-side filesystem operations for a named volume.

fs.read()

Read the entire contents of a file as raw bytes.

Parameters

pathstr
Path relative to the volume root.

Returns

bytes
File contents as raw bytes.

fs.read_text()

Read the entire contents of a file and decode it as UTF-8.

Parameters

pathstr
Path relative to the volume root.

Returns

str
File contents as a string.

fs.write()

Write content to a file, creating it if it doesn’t exist and overwriting if it does.

Parameters

pathstr
Path relative to the volume root.
databytes
File content.

fs.list()

List the entries in a directory.

Parameters

pathstr
Path relative to the volume root.

Returns

Directory entries.

fs.mkdir()

Create a directory and all parent directories.

Parameters

pathstr
Path relative to the volume root.

fs.remove_file()

Remove a file.

Parameters

pathstr
Path relative to the volume root.

fs.exists()

Check whether a path exists within the volume.

Parameters

pathstr
Path relative to the volume root.

Returns

bool
True if the path exists.

Types

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 sandbox volumes dict. stat_virtualization, host_permissions, override_uid, and override_gid apply only to virtiofs-backed mounts (BIND and directory-backed NAMED). Owner IDs must be supplied together, must be integers from 0 through 4294967295, and cannot be combined with StatVirtualization.OFF.

MountKind

Used by MountConfig

String enum (StrEnum) for the type of mount.

VolumeKind

Used by Volume.create() · Volume.named() · VolumeHandle.kind

Storage kind for a named volume.

NamedVolumeMode

Used by Volume.named(mode=…) · MountConfig.named_mode

Creation behavior for a named volume mount.

DiskImageFormat

Used by Volume.disk(), MountConfig

String enum (StrEnum) for the format of a backing disk image.

StatVirtualization

Used by MountConfig.stat_virtualization

Stat virtualization policy for virtiofs-backed mounts.

HostPermissions

Used by MountConfig.host_permissions

Host permission policy for virtiofs-backed mounts.