Skip to main content
Inspect, remove, and prune the local OCI image cache: the images that sandbox creation has already pulled. These APIs are exposed through the public Image class and require a local backend; cloud backends report Unsupported.
import { Image, ImageHandle } from "microsandbox";
import type { ImageDetail, ImagePruneReport } from "microsandbox";

Typical flow

import { Image } from "microsandbox";

for (const image of await Image.list()) {
  console.log(image.reference, image.layerCount);
}

const detail = await Image.inspect("python:3.12");
console.log(detail.config?.workingDir);

const report = await Image.prune();
console.log(report.bytesReclaimed);

Static methods


Image.get()

staticasync
static get(reference: string): Promise<ImageHandle>
Fetch one cached image by reference. Throws an image-not-found error when the reference is not present in the local cache.
const image = await Image.get("python:3.12");
console.log(image.manifestDigest);

Image.list()

staticasync
static list(): Promise<ImageHandle[]>
Return every cached image.
const images = await Image.list();
console.log(images.map((image) => image.reference));

Image.inspect()

staticasync
static inspect(reference: string): Promise<ImageDetail>
Return full detail for a cached image: handle metadata, parsed OCI config fields, and layer metadata.
const detail = await Image.inspect("python:3.12");
for (const layer of detail.layers) {
  console.log(layer.position, layer.diffId);
}

Image.remove()

staticasync
static remove(reference: string, opts?: { force?: boolean }): Promise<void>
Delete a cached image. When force is not set, an image still referenced by one or more sandboxes causes the call to fail.
await Image.remove("old:tag", { force: false });

Image.prune()

staticasync
static prune(): Promise<ImagePruneReport>
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. bytesReclaimed is reported when deleted files could be measured.
const report = await Image.prune();
console.log(report.imageRefsRemoved, report.bytesReclaimed);

Types

ImageHandle

class

Returned by get() · list()

A lightweight metadata handle for a cached OCI image. Properties are read-only.
PropertyTypeDescription
referencestringImage reference
sizeBytesnumber | nullTotal image size in bytes, when known
manifestDigeststring | nullContent-addressable manifest digest
architecturestring | nullResolved architecture
osstring | nullResolved operating system
layerCountnumberNumber of layers
lastUsedAtDate | nullLast referenced time
createdAtDate | nullFirst-pulled time

ImageDetail

interface

Returned by inspect()

Full detail for a cached image.
PropertyTypeDescription
handleImageHandleCore cached image metadata
configImageConfigDetail | nullParsed OCI config block
layersreadonly ImageLayerDetail[]Layers in bottom-to-top order

ImageConfigDetail

interface

Used by ImageDetail.config

OCI image config fields extracted from the local cache.
PropertyTypeDescription
digeststringConfig blob digest
envreadonly string[]Environment variables in KEY=value form
cmdreadonly string[] | nullDefault command
entrypointreadonly string[] | nullImage entrypoint
workingDirstring | nullDefault working directory
userstring | nullDefault user
labelsRecord<string, unknown> | nullOCI labels
stopSignalstring | nullConfigured stop signal

ImageLayerDetail

interface

Used by ImageDetail.layers

Metadata for one image layer.
PropertyTypeDescription
diffIdstringUncompressed diff ID
blobDigeststringCompressed blob digest
mediaTypestring | nullOCI media type
compressedSizeBytesnumber | nullCompressed blob size in bytes
erofsSizeBytesnumber | nullEROFS image size in bytes
positionnumberLayer position, where 0 is the bottom

ImagePruneReport

interface

Returned by prune()

Summary of cached image data removed by Image.prune().
PropertyTypeDescription
imageRefsRemovednumberCached image references removed from the local image index
manifestsRemovednumberOCI manifests removed from the local image index
layersRemovednumberLayer records removed from the local image index
fsmetaRemovednumberMerged fsmeta EROFS artifacts removed from disk
vmdkRemovednumberVMDK descriptor artifacts removed from disk
bytesReclaimednumber | nullBest-effort measured bytes reclaimed from deleted artifacts