Skip to main content
Image is the static namespace for two related things: configuring an explicit rootfs source for a sandbox (Image.oci, Image.bind, Image.disk), and managing the local OCI image cache that sandbox creation pulls into (get, list, inspect, remove, prune). Cache operations require a local backend. See Sandbox for the image= and pull_policy= creation kwargs.

Typical flow

Source factory

These static methods return an ImageSource you can pass as the image= kwarg to Sandbox.create(). A plain string also works (image="python:3.12"); use the factory when you need OCI-only options like the writable upper size, or to be explicit about a bind or disk source.

Image.oci()

Create an OCI image rootfs source. Use upper_size_mib to size the writable overlay upper layer; otherwise the default applies.

Parameters

referencestr
OCI image reference, e.g. “python:3.12”.
upper_size_mibint | None
Writable overlay upper size in MiB. None keeps the default.

Returns

Rootfs source for image=.

Image.bind()

Create a rootfs source that binds a host directory as the guest root filesystem.

Parameters

pathstr
Host directory to use as the rootfs.

Returns

Rootfs source for image=.

Image.disk()

Create a rootfs source backed by a disk image. The format is inferred from the file extension. Pass fstype when the filesystem type cannot be auto-detected.

Parameters

pathstr
Path to the disk image (e.g. .qcow2, .raw, .vmdk).
fstypestr | None
Filesystem type, e.g. “ext4”. None auto-detects.

Returns

Rootfs source for image=.

Cache management

These static methods inspect and prune images already pulled into the local OCI cache. They require a local backend; on a cloud backend they raise UnsupportedError.

Image.get()

Fetch one cached image by reference. Raises ImageNotFoundError when the image is not present in the local cache.

Parameters

referencestr
Image reference to look up.

Returns

Handle to the cached image.

Image.list()

Return every cached image.

Returns

All cached image handles.

Image.inspect()

Return handle metadata plus the parsed OCI config and per-layer detail.

Parameters

referencestr
Image reference to inspect.

Returns

Handle, OCI config, and layers.

Image.remove()

Delete a cached image. When force is False, an image still referenced by one or more sandboxes raises ImageInUseError; pass force=True to remove it anyway.

Parameters

referencestr
Image reference to delete.
forcebool
Remove even if still referenced. Default False.

Image.prune()

Remove cached image data that is not used by any sandbox or indexed snapshot. The returned report counts the removed refs, manifests, layers, fsmeta files, and VMDK files, plus any measured bytes reclaimed.

Returns

Counts of removed data and bytes reclaimed.

Types

ImageSource

Returned by oci() · bind() · disk()

Explicit rootfs image source. Build one with Image.oci(), Image.bind(), or Image.disk(), then pass it as the image= kwarg to Sandbox.create(). A frozen dataclass; treat its fields as opaque.

ImageHandle

Returned by get() · list()

A lightweight handle to a cached OCI image, returned by Image.get() and Image.list(). Properties are read-only attributes; the two methods are async.

ImageDetail

Returned by inspect() · ImageHandle.inspect()

Full detail for a cached image: the core handle, the parsed OCI config block, and per-layer metadata.

ImageConfigDetail

Used by ImageDetail.config

OCI image config fields extracted from the local cache.

ImageLayerDetail

Used by ImageDetail.layers

Metadata for a single image layer.

ImagePruneReport

Returned by prune()

Summary of cached image data removed by Image.prune().

DiskImageFormat

Used by ImageSource._format

Disk image container format. A StrEnum, so the string values are accepted directly.

Errors

Image operations raise these typed exceptions, all subclasses of MicrosandboxError.