Skip to main content
Configure sandbox image sources and manage the local OCI image cache.

Image

Factory for sandbox image sources.

Image.oci()

Create an OCI image rootfs source. Use root_disk to configure its writable layer with a RootDisk factory result. An integer is shorthand for a managed disk of that size in MiB.

Parameters

referencestr
OCI image reference, e.g. “python:3.12”.
root_diskRootDiskConfig | int | None
Writable root disk configuration or managed-disk size in MiB.
upper_size_mibint | None
Deprecated managed-disk size alias. Use root_disk=RootDisk.managed(…).

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.

Local image cache

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.

Image.load()

staticasync
Import images from a local archive into the cache. Accepts docker save tarballs and OCI Image Layout archives, so locally built images can be used without going through a registry.

Parameters

input_pathstr
Path to the archive file, or ”-” to read the archive from stdin.
tagstr | None
Extra reference applied to the first image in the archive.

Returns

A handle for every image reference imported.

Image.save()

staticasync
Export one or more cached images to an archive file. Raises ImageNotFoundError when any reference is not in the local cache, and ValueError for an empty reference list.

Parameters

referencestr | Sequence[str]
Cached image reference to export, or a sequence of references written into the same archive.
output_pathstr
File path to write the archive to.
Archive layout. Defaults to DOCKER.

ImageHandle

class

Returned by get() · list() · load()

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

handle.reference

str Image reference

handle.size_bytes

int \| None Total size in bytes, or None when unknown

handle.manifest_digest

str \| None Content-addressable manifest digest

handle.architecture

str \| None Resolved architecture

handle.os

str \| None Resolved operating system

handle.layer_count

int Number of layers

handle.last_used_at

float \| None Last referenced time, milliseconds since epoch

handle.created_at

float \| None First-pulled time, milliseconds since epoch

handle.inspect()

Fetch full detail for this image

Returns

ImageDetail

handle.remove()

Delete this image (raises ImageInUseError unless force)

RootDisk

Factory for writable OCI root disk configurations.

RootDisk.managed()

Microsandbox-managed sparse ext4 disk

Returns

RootDiskConfig

RootDisk.tmpfs()

Ephemeral RAM-backed upper layer

Returns

RootDiskConfig

RootDisk.disk()

User-supplied writable disk image

Returns

RootDiskConfig

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.

RootDiskConfig

Frozen root disk configuration produced by RootDisk.

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.

ImageArchiveFormat

Used by Image.save(format=…)

Archive layout used when exporting cached images.

ImageSourceKind

Returned in ImageSource._type

Root filesystem source kind.

RootDiskKind

Returned in RootDiskConfig.kind

Writable OCI root disk implementation.

Errors

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