ImageBuilder automates the creation of VM images with SSH server pre-configured. It uses Docker to build minimal Alpine or Debian-based rootfs images, complete with networking and a custom init script.
Since v0.0.14, Debian is no longer a CLI
--os value. The auto-config path (smolvm sandbox create --os ...) currently accepts alpine, ubuntu, and windows; Windows guests require --image because they boot from a prebuilt qcow2. The build_debian_ssh_key method below remains callable when you instantiate ImageBuilder directly, but it is no longer wired into the CLI’s --os flag.The optional
kernel_url parameter on each build method is retained for backward compatibility. Since v0.0.14, SmolVM ships its own universal kernel and uses it by default — you only need to override kernel_url for advanced custom-kernel scenarios.Constructor
ImageBuilder(cache_dir=None)
Initialize the image builder.
Path | None
default:"~/.smolvm/images/"
Directory to store built images. If not specified, defaults to
~/.smolvm/images/.Methods
check_docker()
Check if Docker is installed and the daemon is reachable.
bool
Returns
True if Docker is available and the daemon responds, False otherwise.docker_requirement_error()
Create a diagnostic ImageError with a specific message based on what is wrong with Docker. This method inspects the Docker installation and returns a targeted error that tells the user exactly how to fix the problem.
The method distinguishes between these scenarios:
- Docker not installed — prompts to install Docker Desktop or
docker.io - Daemon not running — prompts to start Docker Desktop or the Docker service
- Permission denied on socket — prompts to grant access to
/var/run/docker.sock - Daemon timeout — reports that Docker is not responding
- Other errors — includes the original Docker error output for debugging
ImageError
An
ImageError with a human-readable message describing the problem and how to fix it.You don’t need to call this method directly in most cases. All build methods (
build_alpine_ssh, build_alpine_ssh_key, build_debian_ssh_key) automatically call it and raise the resulting ImageError when Docker is unavailable.build_alpine_ssh(name, ssh_password, rootfs_size_mb, kernel_url)
Build an Alpine Linux image with SSH server configured for password authentication.
Uses Docker to create a minimal Alpine Linux rootfs with:
- OpenSSH server configured and auto-starting
- Root password authentication
- Custom
/initscript that sets up networking and starts sshd - DNS resolution configured
boot_args containing init=/init so the custom init script runs. Use the SSH_BOOT_ARGS constant for convenience.
str
default:"alpine-ssh"
Image name for caching. Images are stored in
{cache_dir}/{name}/.str
default:"smolvm"
Root password for SSH authentication.
int
default:"512"
Size of rootfs in megabytes.
str | None
default:"None"
Optional kernel URL override. If not provided, downloads a Firecracker-compatible kernel for the host architecture.
tuple[Path, Path]
Tuple of
(kernel_path, rootfs_path) pointing to the built image files.ImageError- If Docker is not available or build fails
build_alpine_ssh_key(ssh_public_key, name, rootfs_size_mb, kernel_url)
Build an Alpine Linux image with key-only SSH access (no password authentication).
str | Path
required
Public key content (string starting with “ssh-”) or path to a public key file.
str
default:"alpine-ssh-key"
Image name for caching.
int
default:"512"
Size of rootfs in megabytes.
str | None
default:"None"
Optional kernel URL override.
tuple[Path, Path]
Tuple of
(kernel_path, rootfs_path).ImageError- If Docker is not available, build fails, or SSH key format is invalid
build_debian_ssh_key(ssh_public_key, name, rootfs_size_mb, base_image, kernel_url)
Build a Debian Linux image with key-only SSH access.
This method creates a larger, more feature-complete image based on Debian. It’s suitable for applications that need a full Linux environment with standard utilities.
str | Path
required
Public key content (string starting with “ssh-”) or path to a public key file.
str
default:"debian-ssh-key"
Image name for caching.
int
default:"2048"
Size of rootfs in megabytes. Debian images require more space than Alpine.
str
default:"debian:bookworm-slim"
Docker base image to build from.
str | None
default:"None"
Optional kernel URL override.
tuple[Path, Path]
Tuple of
(kernel_path, rootfs_path).ImageError- If Docker is not available, build fails, or SSH key format is invalid
Constants
SSH_BOOT_ARGS
Default boot arguments for VMs built with SSH support.
console=ttyS0- Serial console outputreboot=k- Reboot via keyboard controllerpanic=1- Reboot 1 second after kernel panicpci=off- Disable PCI bus scanning (not needed in microVMs)root=/dev/vda- Root filesystem devicerw- Mount root as read-writeinit=/init- Use custom init script at/init
init=/init parameter is required for SSH-enabled images to work properly. The custom init script handles:
- Mounting essential filesystems (
/proc,/sys,/dev) - Configuring networking from kernel command line
- Setting up DNS resolution
- Starting the SSH daemon
- Signal handling for clean shutdown
Image Caching
All built images are cached to avoid rebuilding. For key-based images (build_alpine_ssh_key and build_debian_ssh_key), the cache is invalidated and rebuilt if the SSH key file is newer than the cached image.
Related
- ImageManager - Download and cache pre-built images
- ImageSource - Define downloadable image metadata
- BootImage - Describe a bootable custom root filesystem
- DockerRootfsBuilder - Build a custom root filesystem from a Dockerfile
smolvm image build- Same build pipeline exposed as a CLI command- VMConfig - Configure VM instances
