A typed Go client for the local Firecracker API
English · 简体中文
Use this SDK to configure and control a Firecracker microVM over its Unix API socket.
With Go 1.27.2 or later, run this from your application's Go module:
go get github.com/JianyueLab/firecracker-sdkStart Firecracker separately with its API socket enabled. Pass the socket path to NewClient, then call GetVersion to verify the connection. This does not start or modify a microVM.
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/JianyueLab/firecracker-sdk"
)
func main() {
client, err := firecracker.NewClient("/run/firecracker/api.sock", firecracker.WithTimeout(5*time.Second))
if err != nil {
log.Fatal(err)
}
defer client.CloseIdleConnections()
version, err := client.GetVersion(context.Background())
if err != nil {
log.Print(err)
return
}
fmt.Println(version.FirecrackerVersion)
}Replace /run/firecracker/api.sock with your instance's socket path. A Firecracker v1.18.0 instance prints 1.18.0.
The SDK targets Firecracker v1.18.0. It covers instance inspection, boot and machine configuration, VM lifecycle actions, devices and rate limits, MMDS, snapshots, logging, and metrics. Firecracker determines which operations are available for the current VM state and host configuration.
Clients can be reused concurrently. API methods accept a context.Context, and unexpected HTTP statuses return a *firecracker.APIError that can be inspected with errors.As. Use GetMMDSRaw to read metadata whose top-level JSON value is not an object.
See the Go examples for configuring and starting a microVM or handling API errors. Paths passed to Firecracker, such as kernel or disk paths, must be valid from the Firecracker process's point of view, including inside its jail root when applicable.