Skip to main content
SmolVM provides a comprehensive exception hierarchy for handling various error conditions. All exceptions inherit from the base SmolVMError class, making it easy to catch all SmolVM-related errors or handle specific error types.

Exception Hierarchy

Base Exception

SmolVMError

Base exception for all SmolVM errors. All other exceptions inherit from this class. Attributes:
  • message (str): Human-readable error message
  • details (dict): Additional error context and metadata
Example:

VM Lifecycle Exceptions

VMAlreadyExistsError

Raised when attempting to create a VM with an ID that already exists. Attributes:
  • vm_id (str): The conflicting VM ID
  • message (str): Error message
  • details (dict): Contains vm_id
When raised:
  • Creating a new VM when a VM with the same ID already exists
Example:

VMNotFoundError

Raised when attempting to access a VM that doesn’t exist. Attributes:
  • vm_id (str): The VM ID that was not found
  • message (str): Error message
  • details (dict): Contains vm_id
When raised:
  • Calling SmolVM.from_id() with a non-existent VM ID
  • Attempting operations on a deleted VM
Example:

Snapshot Exceptions

SnapshotAlreadyExistsError

Raised when attempting to create a snapshot with an ID that already exists. Attributes:
  • snapshot_id (str): The conflicting snapshot ID
  • message (str): Error message
  • details (dict): Contains snapshot_id
When raised:
  • Creating a snapshot when one with the same ID already exists
Example:

SnapshotNotFoundError

Raised when attempting to access a snapshot that doesn’t exist. Attributes:
  • snapshot_id (str): The snapshot ID that was not found
  • message (str): Error message
  • details (dict): Contains snapshot_id
When raised:
  • Calling SmolVM.from_snapshot() with a non-existent snapshot ID
  • Attempting to delete or restore a missing snapshot
Example:

Validation Exceptions

ValidationError

Raised when input validation fails, such as invalid configuration parameters. When raised:
  • Invalid VM configuration (e.g., invalid CPU count, memory size)
  • Invalid network configuration
  • Invalid image paths or URLs
  • Malformed parameters
Example:

Network Exceptions

NetworkError

Raised when network operations fail, including TAP device creation, NAT configuration, or IP allocation. When raised:
  • Failed to create TAP device
  • Failed to configure NAT rules
  • IP address allocation errors
  • Network interface configuration failures
Example:

Host Environment Exceptions

HostError

Raised when host environment checks fail, such as missing KVM support, dependencies, or Firecracker binary. When raised:
  • KVM is not available or accessible
  • Firecracker binary not found
  • Missing system dependencies
  • Insufficient permissions for virtualization
Example:

Image Exceptions

ImageError

Raised when image operations fail, including download errors, checksum validation, or cache issues. When raised:
  • Failed to download kernel or rootfs image
  • Checksum verification failed
  • Cache directory access errors
  • Image file corruption
Example:

Firecracker API Exceptions

FirecrackerAPIError

Raised when Firecracker API calls fail. Attributes:
  • status_code (int | None): HTTP status code from Firecracker API
  • message (str): Error message
  • details (dict): Contains status_code
When raised:
  • Firecracker API returns an error response
  • Failed to communicate with Firecracker socket
  • Invalid API requests
Example:

Timeout Exceptions

OperationTimeoutError

Raised when an operation exceeds its timeout duration. Attributes:
  • operation (str): Name of the operation that timed out
  • timeout_seconds (float): Timeout duration in seconds
  • message (str): Error message
  • details (dict): Contains operation and timeout_seconds
When raised:
  • VM boot timeout
  • Command execution timeout
  • API call timeout
Example:

TimeoutError

Backward-compatible alias for OperationTimeoutError. Use OperationTimeoutError in new code.

Command Execution Exceptions

CommandExecutionUnavailableError

Raised when command execution is not available for a VM, typically because the VM profile doesn’t support SSH. Attributes:
  • vm_id (str): The VM ID
  • reason (str): Why command execution is unavailable
  • remediation (str | None): Suggested fix if available
  • message (str): Error message with reason and remediation
  • details (dict): Contains vm_id and reason
When raised:
  • Attempting to run commands on a VM without SSH support
  • SSH is not configured in the kernel boot arguments
  • VM is not running or not accessible
Example:

CommandBlockedError

Raised by SmolVM.run() when an on_pre_run callback vetoes a command before it reaches the guest. Attributes:
  • vm_id (str | None): The VM the command targeted
  • command (str | None): The blocked command string
  • message (str): Human-readable reason for the block
  • details (dict): Contains vm_id and command
When raised:
  • A registered Callback raises CommandBlockedError from its on_pre_run hook
  • Any other exception raised by a pre-run callback also propagates from run()
Example:
See the Callback reference for full details on the hook contract.

Error Handling Best Practices

Catch Specific Exceptions

Catch specific exceptions when you can handle them appropriately:

Catch All SmolVM Errors

Use the base SmolVMError to catch all SmolVM-related errors:

Access Error Details

All exceptions provide a details dictionary with additional context:

Cleanup on Error

Always clean up resources when errors occur:
Or use context managers for automatic cleanup:
Last modified on June 2, 2026