A Rust SDK for interacting with the Firecracker microVM REST API.
This SDK is generated from the official Firecracker OpenAPI specification (firecracker.yaml) and extended with hand-crafted abstractions (Machine and MicroVm) to seamlessly manage Firecracker instances via Unix Domain Sockets in Rust.
- Full API Coverage: Generated models and endpoints covering the complete Firecracker API spec.
- Async client: Uses
tokioandhyperto communicate efficiently with the Firecracker REST API over completely local Unix sockets. - High-level abstractions: Spin up new Firecracker processes and manage their lifetimes effortlessly using the
Machinewrapper.
use std::{borrow::Cow, path::PathBuf};
use firecracker_rust_sdk::machine::{Machine, MachineConfig};
use uuid::Uuid;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = MachineConfig {
vm_id: Uuid::new_v4(),
socket_path: Cow::Owned(PathBuf::from("/tmp/firecracker.sock")),
exec_path: Cow::Owned(PathBuf::from("/usr/local/bin/firecracker")),
};
let mut vm = Machine::connect(config).await?;
let info = vm.describe_instance().await?;
println!("VM State: {:?}", info.state);
Ok(())
}We provide several standalone examples demonstrating how to boot and control microVMs in the examples/ directory.
- Download the Firecracker binary:
wget https://github.com/firecracker-microvm/firecracker/releases/download/v1.15.1/firecracker-v1.15.1-x86_64 -O firecracker
chmod +x firecracker- Fetch the test images (Alpine kernel & rootfs) via our helper script:
./examples/fetch_test_images.sh- Run the complete Alpine booting example:
cargo run --example simple_vm_alpine- You can attach to the microVM console through the tmux session it spawned (the example output will provide the exact command, e.g.,
tmux attach -t vm_<uuid>).
cargo run --example simple_vm_alpine– Downloads an Alpine kernel/rootfs and fully boots an instance.cargo run --example simple_vm– A minimal example template requiring you to provide your own kernel/rootfs (vmlinuxandrootfs.ext4) and set up a TAP networking device.cargo run --example connect -- /tmp/firecracker.sock– Connects to a running instance and prints diagnostics.cargo run --example shutdown_vm -- /tmp/firecracker.sock– Connects to a running instance and safely shuts it down by sending Ctrl+Alt+Del.
See examples/README.md for more details.
The SDK models and base API clients are generated from firecracker.yaml.
If you need to update the API version:
# Downloads the openapi-generator-cli and re-generates the code
make regenerate