Image
Factory for sandbox image sources.Image.oci()
Example
Example
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
referencestrOCI image reference, e.g.
“python:3.12”.root_diskRootDiskConfig | int | NoneWritable root disk configuration or managed-disk size in MiB.
upper_size_mibint | NoneDeprecated managed-disk size alias. Use
root_disk=RootDisk.managed(…).Returns
Rootfs source for
image=.Image.bind()
Example
Example
Parameters
pathstrHost directory to use as the rootfs.
Returns
Rootfs source for
image=.Image.disk()
Example
Example
fstype when the filesystem type cannot be auto-detected.
Parameters
pathstrPath to the disk image (e.g.
.qcow2, .raw, .vmdk).fstypestr | NoneFilesystem 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()
Example
Example
ImageNotFoundError when the image is not present in the local cache.
Parameters
referencestrImage reference to look up.
Returns
Handle to the cached image.
Image.list()
Example
Example
Returns
All cached image handles.
Image.inspect()
Example
Example
Parameters
referencestrImage reference to inspect.
Returns
Handle, OCI config, and layers.
Image.remove()
Example
Example
force is False, an image still referenced by one or more sandboxes raises ImageInUseError; pass force=True to remove it anyway.
Parameters
referencestrImage reference to delete.
forceboolRemove even if still referenced. Default
False.Image.prune()
Example
Example
Returns
Counts of removed data and bytes reclaimed.
Example
Example
Image.load()
docker save tarballs and OCI Image Layout archives, so locally built images can be used without going through a registry.
Parameters
input_pathstrPath to the archive file, or
”-” to read the archive from stdin.tagstr | NoneExtra reference applied to the first image in the archive.
Returns
A handle for every image reference imported.
Example
Example
Image.save()
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_pathstrFile path to write the archive to.
formatImageArchiveFormatArchive layout. Defaults to
DOCKER.Example
Example
ImageHandle
Returned by get() · list() · load()
A lightweight handle to a cached OCI image, returned byImage.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()
Returns
ImageDetail
handle.remove()
ImageInUseError unless force)
RootDisk
Factory for writable OCI root disk configurations.RootDisk.managed()
Returns
RootDiskConfig
RootDisk.tmpfs()
Returns
RootDiskConfig
RootDisk.disk()
Returns
RootDiskConfig
Types
ImageSource
Returned by oci() · bind() · disk()
Explicit rootfs image source. Build one withImage.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 byRootDisk.
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 byImage.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 ofMicrosandboxError.