Overview
VMConfig is a Pydantic model that defines the configuration for creating a microVM. It specifies CPU, memory, kernel, rootfs, and other runtime settings.
Model Definition
Fields
Unique identifier for the VM. Must be lowercase alphanumeric with hyphens, matching the pattern
^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$ or ^[a-z0-9]$.If omitted or explicitly set to None, SmolVM auto-generates an ID in the format vm-<8-char-hex>.Number of virtual CPUs. Valid range: 1-32.
Memory size in MiB (mebibytes). Valid range: 128-16384.
Path to the kernel image file. The path must exist and point to a valid file.
Path to the root filesystem image. The path must exist and point to a valid file.
Kernel boot arguments. For SSH-capable VMs built with ImageBuilder, include
init=/init.Runtime backend override. Valid options:
"firecracker": Use Firecracker VMM"qemu": Use QEMUNoneor"auto": Auto-detect based on host capabilities
Disk lifecycle mode:
"isolated": Clone rootfs per VM for sandbox isolation. Each VM gets its own copy."shared": Boot directly fromrootfs_path. Multiple VMs can share the same disk image.
Whether to keep the isolated VM disk after deletion. When
True, a later create operation with the same VM ID can reuse prior disk state.Only applies when disk_mode="isolated".Environment variables to inject into the guest after boot via SSH. Keys must be valid shell identifiers (matching
^[a-zA-Z_][a-zA-Z0-9_]*$).Variables are persisted in /etc/profile.d/smolvm_env.sh and affect new SSH sessions/login shells.Requires an SSH-capable image (boot args must contain init=/init).Validation Rules
Path Validation
Bothkernel_path and rootfs_path are validated to ensure:
- The path exists on the filesystem
- The path points to a file (not a directory)
Environment Variable Validation
All keys inenv_vars must be valid shell identifiers:
- Start with a letter or underscore
- Contain only letters, numbers, and underscores
- Pattern:
^[a-zA-Z_][a-zA-Z0-9_]*$
ValidationError during model instantiation.
VM ID Validation
Thevm_id must:
- Be lowercase
- Start and end with alphanumeric characters
- Contain only lowercase letters, numbers, and hyphens
- Be 1-64 characters long
Usage Examples
Basic Configuration
Custom VM ID and Resources
SSH-Capable VM with Environment Variables
Shared Disk Mode
Persistent Isolated Disk
QEMU Backend
Immutability
VMConfig instances are frozen and cannot be modified after creation:Integration with SmolVM
Pass VMConfig to the SmolVM constructor:Building Images for VMConfig
UseImageBuilder to create kernel and rootfs images:
Field Summary
| Field | Type | Default | Range/Validation |
|---|---|---|---|
vm_id | str | Auto-generated | ^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$ |
vcpu_count | int | 2 | 1-32 |
mem_size_mib | int | 512 | 128-16384 |
kernel_path | Path | Required | Must exist as file |
rootfs_path | Path | Required | Must exist as file |
boot_args | str | "console=ttyS0 reboot=k panic=1 pci=off" | Any string |
backend | str | None | None | "firecracker", "qemu", None |
disk_mode | Literal | "isolated" | "isolated", "shared" |
retain_disk_on_delete | bool | False | True, False |
env_vars | dict[str, str] | {} | Keys must be valid shell identifiers |