Skip to main content
ImageManager handles fetching and caching VM images from remote sources. It provides atomic downloads with SHA-256 verification to ensure image integrity.

Constructor

ImageManager(cache_dir=None, registry=None)

Initialize the image manager.
cache_dir
Path | None
default:"~/.smolvm/images/"
Override the default cache directory. If not specified, images are cached in ~/.smolvm/images/.
registry
dict[str, ImageSource] | None
default:"BUILTIN_IMAGES"
Override the built-in image registry. Useful for testing or adding custom images. If not specified, uses the built-in registry.

Methods

list_available()

List names of all registered images.
return
list[str]
Sorted list of image names available in the registry.

is_cached(name)

Check if an image is fully cached locally.
name
str
required
Image name to check.
return
bool
True if both kernel and rootfs files exist in the cache, False otherwise.
Raises:
  • ValueError - If image name is empty

ensure_image(name)

Ensure an image is available locally, downloading if necessary. If the image is already cached and passes SHA-256 verification, it is returned immediately. Otherwise, it is downloaded from the registry. Downloads are atomic: files are written to a temporary location, SHA-256 verified, then renamed into place. This ensures a partial download never corrupts the cache.
name
str
required
Image name from the registry.
return
LocalImage
LocalImage instance with paths to kernel and rootfs.
Raises:
  • ValueError - If image name is empty
  • ImageError - If the image is not in the registry, download fails, or checksum verification fails

Built-in Image Registry

SmolVM includes a registry of pre-built images from Firecracker’s official sources:

hello

Minimal “hello world” image for testing.
  • Kernel: hello-vmlinux.bin
  • Rootfs: hello-rootfs.ext4
  • Size: ~10MB total
  • Use case: Quick tests, examples

quickstart-x86_64

Ubuntu Bionic (18.04) image for x86_64 architecture.
  • Kernel: vmlinux.bin
  • Rootfs: bionic.rootfs.ext4
  • Size: ~100MB total
  • Use case: General purpose Linux environment

Custom Image Registry

You can define custom images by providing your own registry:

Cache Behavior

The image manager implements smart caching:
  1. Cache hit: If both kernel and rootfs exist and pass SHA-256 verification, they are used immediately
  2. Cache miss: If files don’t exist, they are downloaded
  3. Checksum mismatch: If cached files fail verification, they are re-downloaded
  4. Atomic writes: Downloads write to temporary files and rename on success, preventing corruption

Error Handling

Last modified on May 5, 2026