Skip to main content
Inspect, remove, and prune the local OCI image cache: the images that sandbox creation has already pulled. The ambient Image::* methods use the active default backend and return Unsupported when that backend is cloud. The *_local variants take an explicit LocalBackend and never consult ambient backend state.
use microsandbox::{Image, ImagePruneReport};

Typical flow

use microsandbox::Image;

for image in Image::list().await? {
    println!("{} ({} layers)", image.reference(), image.layer_count());
}

let detail = Image::inspect("python:3.12").await?;
println!("{:?}", detail.config.as_ref().and_then(|c| c.working_dir.as_deref()));

let report = Image::prune().await?;
println!("removed {} refs", report.image_refs_removed);

Ambient cache methods

These methods resolve the active backend with microsandbox::backend::default_backend(). They are convenient for normal local programs and fail with Unsupported when the active backend is cloud.

Image::get()

async fn get(reference: &str) -> MicrosandboxResult<ImageHandle>
let image = Image::get("python:3.12").await?;
println!("{:?}", image.manifest_digest());
Fetch one cached image by reference. Returns ImageNotFound when the reference is not present in the local cache.

Image::list()

async fn list() -> MicrosandboxResult<Vec<ImageHandle>>
for image in Image::list().await? {
    println!("{}", image.reference());
}
Return every cached image, ordered by creation time with newest first.

Image::inspect()

async fn inspect(reference: &str) -> MicrosandboxResult<ImageDetail>
let detail = Image::inspect("python:3.12").await?;
for layer in &detail.layers {
    println!("{} {}", layer.position, layer.diff_id);
}
Return full detail for a cached image: handle metadata, parsed OCI config fields, and layer metadata.

Image::remove()

async fn remove(reference: &str, force: bool) -> MicrosandboxResult<()>
Image::remove("old:tag", false).await?;
Delete a cached image. When force is false, an image still referenced by one or more sandboxes returns ImageInUse.

Image::prune()

async fn prune() -> MicrosandboxResult<ImagePruneReport>
let report = Image::prune().await?;
println!("{:?}", report.bytes_reclaimed);
Remove cached image data that is not used by any sandbox or indexed snapshot. Prune removes unused image refs, manifests that become unreachable, orphaned layers, image metadata on disk, layer EROFS artifacts, fsmeta EROFS artifacts, and VMDK descriptor artifacts. bytes_reclaimed is reported when deleted files could be measured.

Explicit local variants

Use these when your program owns a specific LocalBackend and should not depend on the process default backend.
use microsandbox::{Image, LocalBackend};

let backend = LocalBackend::builder()
    .home("/tmp/msb-home")
    .build()
    .await?;

let image = Image::get_local(&backend, "python:3.12").await?;
let images = Image::list_local(&backend).await?;
let detail = Image::inspect_local(&backend, image.reference()).await?;
Image::remove_local(&backend, detail.handle.reference(), false).await?;
let report = Image::prune_local(&backend).await?;
MethodSignature
get_localasync fn get_local(local: &LocalBackend, reference: &str) -> MicrosandboxResult<ImageHandle>
list_localasync fn list_local(local: &LocalBackend) -> MicrosandboxResult<Vec<ImageHandle>>
inspect_localasync fn inspect_local(local: &LocalBackend, reference: &str) -> MicrosandboxResult<ImageDetail>
remove_localasync fn remove_local(local: &LocalBackend, reference: &str, force: bool) -> MicrosandboxResult<()>
prune_localasync fn prune_local(local: &LocalBackend) -> MicrosandboxResult<ImagePruneReport>

Types

ImageHandle

Returned by get() · list()

A lightweight metadata handle for a cached OCI image.
MethodReturnsDescription
reference()&strImage reference
size_bytes()Option<i64>Total image size in bytes, when known
manifest_digest()Option<&str>Content-addressable manifest digest
architecture()Option<&str>Resolved architecture
os()Option<&str>Resolved operating system
layer_count()usizeNumber of layers
last_used_at()Option<DateTime<Utc>>Last referenced time
created_at()Option<DateTime<Utc>>First-pulled time

ImageDetail

Returned by inspect()

Full detail for a cached image.
FieldTypeDescription
handleImageHandleCore cached image metadata
configOption<ImageConfigDetail>Parsed OCI config block
layersVec<ImageLayerDetail>Layers in bottom-to-top order

ImageConfigDetail

Used by ImageDetail.config

OCI image config fields extracted from the local cache.
FieldTypeDescription
digestStringConfig blob digest
envVec<String>Environment variables in KEY=value form
cmdOption<Vec<String>>Default command
entrypointOption<Vec<String>>Image entrypoint
working_dirOption<String>Default working directory
userOption<String>Default user
labelsOption<serde_json::Value>OCI labels
stop_signalOption<String>Configured stop signal

ImageLayerDetail

Used by ImageDetail.layers

Metadata for one image layer.
FieldTypeDescription
diff_idStringUncompressed diff ID
blob_digestStringCompressed blob digest
media_typeOption<String>OCI media type
compressed_size_bytesOption<i64>Compressed blob size in bytes
erofs_size_bytesOption<i64>EROFS image size in bytes
positioni32Layer position, where 0 is the bottom

ImagePruneReport

Returned by prune()

Summary of cached image data removed by Image::prune().
FieldTypeDescription
image_refs_removedu32Cached image references removed from the local image index
manifests_removedu32OCI manifests removed from the local image index
layers_removedu32Layer records removed from the local image index
fsmeta_removedu32Merged fsmeta EROFS artifacts removed from disk
vmdk_removedu32VMDK descriptor artifacts removed from disk
bytes_reclaimedOption<u64>Best-effort measured bytes reclaimed from deleted artifacts