Error Types
Exception Hierarchy
BoxliteError
Base exception for all BoxLite errors. Catch this to handle any BoxLite-specific error.
ExecError
Raised when a command execution fails (non-zero exit code).
| Attribute | Type | Description |
|---|---|---|
command | str | The command that failed |
exit_code | int | Non-zero exit code |
stderr | str | Standard error output |
TimeoutError
Raised when an operation times out.
ParseError
Raised when output parsing fails.
Core Error Variants
BoxLite uses a centralized error enum internally. These are surfaced asBoxliteError exceptions in Python with descriptive messages.
UnsupportedEngine
Platform or hypervisor not supported.
Cause:
- Running on Windows
- Running on Intel Mac
- KVM not available on Linux
- Hypervisor.framework not available on macOS
- Use supported platform (macOS ARM64, Linux x86_64/ARM64)
- Verify hypervisor availability:
- Linux:
grep -E 'vmx|svm' /proc/cpuinfo - macOS: Ensure macOS 12+ on Apple Silicon
- Linux:
Engine(String)
Hypervisor or VM engine error.
Cause:
- KVM module not loaded
- Insufficient permissions for
/dev/kvm - Hypervisor.framework error
- VM creation failed
Config(String)
Invalid box configuration.
Cause:
- Invalid CPU count (< 1 or > host CPUs)
- Invalid memory size (< 128 or > 65536)
- Invalid paths in volumes
- Invalid port numbers
- Verify configuration parameters are within valid ranges
- Check file paths exist for volume mounts
- Ensure port numbers are valid (1-65535)
Storage(String)
Filesystem or disk operation error.
Cause:
- Disk full (
~/.boxlitepartition) - Permission denied writing to
~/.boxlite - Disk image creation failed
- QCOW2 operation failed
Image(String)
OCI image pull or extraction error.
Cause:
- Network connectivity issues
- Invalid image name or tag
- Registry authentication required
- Image not found in registry
- Corrupted image layers
Portal(String)
Host-guest communication error (gRPC over vsock).
Cause:
- Guest agent not responding
- vsock connection failed
- gRPC timeout
- Guest initialization failed
- Enable debug logging:
RUST_LOG=debug - Check if box is running:
box.info().status - Restart box:
box.stop()and recreate - Report issue with logs if persists
Network(String)
Network configuration or connectivity error.
Cause:
- gvproxy not running or crashed
- Port already in use
- Network backend initialization failed
Execution(String)
Command execution error.
Cause:
- Command not found in image
- Command crashed or killed
- Execution timeout
- Streaming I/O error
-
Verify command exists in image:
-
Check exit code and stderr:
Internal(String)
Internal BoxLite error.
Cause:
- Unexpected internal state
- I/O error
- JSON parsing error
- Unhandled edge case
- Enable debug logging:
RUST_LOG=debug python script.py - Report issue with full logs to GitHub
- Include BoxLite version, platform, and reproduction steps
NotFound(String)
Box or resource not found.
Cause:
- Box ID does not exist
- Box was removed
- Image not in cache
- List all boxes:
runtime.list() - Verify box ID is correct
- Create new box if needed
AlreadyExists(String)
Box or resource already exists.
Cause:
- Duplicate box creation attempt
- Port already forwarded
- Use existing box:
runtime.get(box_id) - Remove existing box:
box.remove() - Use different configuration (e.g., different port)
InvalidState(String)
Box is in wrong state for requested operation.
Cause:
- Executing command on stopped box
- Stopping already stopped box
- Restarting box that never started
- Check box status:
info = await box.info(); print(info.status) - Restart box if stopped:
runtime.get(box_id)(may auto-restart) - Create new box if needed
Error Handling Patterns
Basic Error Handling
Catching Specific Errors
Retry Pattern
Metrics
boxlite.RuntimeMetrics
Aggregate metrics across all boxes managed by a runtime instance.
| Field | Type | Description |
|---|---|---|
boxes_created | int | Total boxes created |
boxes_destroyed | int | Total boxes destroyed |
total_exec_calls | int | Total command executions |
active_boxes | int | Currently running boxes |
boxlite.BoxMetrics
Per-box resource usage metrics. Retrieved via box.metrics().
| Field | Type | Description |
|---|---|---|
cpu_time_ms | int | Total CPU time in milliseconds |
memory_usage_bytes | int | Current memory usage in bytes |
network_bytes_sent | int | Total bytes sent |
network_bytes_received | int | Total bytes received |
Monitoring Example
Runtime-wide Monitoring
See Also
- Python SDK Overview - Runtime management, installation
- Box Types - SimpleBox, CodeBox, and other box types
- Execution - Command execution reference
- Configuration Reference - BoxOptions details and error codes