virtle

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 22 Imported by: 0

README

Virtle the Space Turtle

virtle 🐢🪐

Virtle is a VM manager for sandbox workflows.

Status: Beta. Used day-to-day by a few people, feedback appreciated.

Background: Originally designed to be used with agentspace, a NixOS-based sandbox builder, but virtle has been refined enough to act as a standalone tool.

How does it work?

virtle reads a manifest, starts the required host processes, launches QEMU, waits for guest SSH readiness, attaches an active session with --ssh.

It also handles teardown, QMP-based shutdown, disk-backed suspend/resume, runtime vsock CID allocation, QGA-based remote commands, and more.

Features
  • Runs a QEMU microvm.
  • Allocates block overlay images.
  • Manages virtiofsd daemons for virtiofs mounts.
  • Provisions SSH between host and guest.
  • Connects over SSH upon boot via signaling.
  • Writes files between guest and host on boot or shutdown.
  • Suspend and resume.
  • Notification execution hooks.
  • Exposes a virtle.sock for RPC (also usable via virtle rpc sub-command).
  • (Experimental) Balloon memory: Auto-adjust memory available to the VM based on internal memory pressure metrics.
  • (Experimental) Hotplug: Attach/detach devices during runtime (requires full VM).

Usage

First, write a simple manifest and save it as manifest.toml. See: ./examples/manifest-*.toml.

Global flags:

  • virtle [--manifest=MANIFEST] ... - When --manifest is omitted, ./manifest.toml is used, falling back to ./manifest.json. Manifests may be TOML or JSON.
  • virtle -v ... - Show useful VM and SSH lifecycle information.
  • virtle -vv ... - Show debugging details and output from background commands.
  • virtle --version - Print the virtle version and exit.

Launch a VM:

  • virtle launch [--ssh] [--resume=no|auto|force] [-- <remote-cmd...>]

Other advanced features:

  • virtle suspend
  • virtle status
  • virtle rpc METHOD [JSON_ARGS]
  • virtle hotplug ID (experimental)
  • virtle hotplug --detach ID (experimental)
Manifest

There are some handy sub-commands for working with manifest files:

  • virtle manifest defaults [--resolved]
  • virtle manifest validate
  • virtle manifest resolve
  • virtle manifest schema

Manifest exec arrays render each argv element as a Go text/template. The host process environment is available as .Env on every surface.

Surface Template values Injected environment
qemu.exec HostName, WorkingDir, StateDir, HostOS, HostArch, HostSystem, .Env none
qemu.fwd_tunnel_exec Host, Port, .Env none; QEMU starts the command
ssh.exec CID, User, Destination, .Env CID, USER, DESTINATION
mounts[type=virtiofs].virtiofs Socket, MountSource, MountTag, CID, StateDir, .Env SOCKET, MOUNT_SOURCE, MOUNT_TAG, CID, STATE_DIR, VIRTIOFSD_SOCKET
run[].exec CID, StateDir, Workspace.GuestPath, Workspace.HostPath, user vars, .Env scalar top-level values only
notifications.exec State, Message, notification context values, .Env STATE, MESSAGE, normalized context values, VIRTLE_NOTIFY_STATE, VIRTLE_NOTIFY_MESSAGE, VIRTLE_NOTIFY_CONTEXT_<KEY>

Library

Virtle library docs: https://pkg.go.dev/github.com/shazow/virtle

Boot a VM, run a command, tear down:

spec := &vm.Spec{
	Kernel: vm.Kernel{Path: "vmlinuz", Initrd: "initrd.img"},
	Shares: []vm.Share{{Tag: "src", HostPath: ".", GuestPath: "/workspace"}},
	Memory: 2048 * units.Mebibyte,
}
b := &qemu.Backend{
	RemoteControl: qemu.QGA{},
	Logger:        slog.Default(),
}
m, err := b.Start(ctx, spec)
if err != nil {
	log.Fatal(err)
}
defer m.Shutdown(ctx)

g, err := m.RemoteControl()
if err != nil {
	log.Fatal(err) // this VM has no guest agent
}
err = g.Run(ctx, &vm.GuestCmd{Path: "make", Dir: "/workspace", Stdout: os.Stdout})

Optional functionality is discovered by type assertion, as in database/sql/driver:

if s, ok := m.(backend.Suspender); ok {
	err = s.Suspend(ctx)
} else {
	err = m.Shutdown(ctx)
}

Or drive it from a manifest, as the CLI does:

spec, b, err := manifest.Load(f)
m, err := b.Start(ctx, spec)

License

MIT

Documentation

Overview

Command virtle launches and controls QEMU sandbox VMs described by a manifest. Run virtle --help for the command list; see README.md for the manifest format.

Directories

Path Synopsis
Package backend defines the implementer contract for virtle VM backends, mirroring the database/sql/driver split: consumers hold the interfaces declared here, implementations live in backend-named subpackages (backend/qemu today).
Package backend defines the implementer contract for virtle VM backends, mirroring the database/sql/driver split: consumers hold the interfaces declared here, implementations live in backend-named subpackages (backend/qemu today).
backendtest
Package backendtest provides backend conformance tests and an in-memory backend factory for unit tests.
Package backendtest provides backend conformance tests and an in-memory backend factory for unit tests.
qemu
Package qemu implements a virtle backend that launches virtual machines with QEMU.
Package qemu implements a virtle backend that launches virtual machines with QEMU.
qemu/internal/balloon
Package balloon implements the internal virtio-balloon feature.
Package balloon implements the internal virtio-balloon feature.
qemu/internal/hotplug
Package hotplug attaches and detaches runtime devices for a running VM.
Package hotplug attaches and detaches runtime devices for a running VM.
qemu/internal/launch
Package launch contains the host-side building blocks shared by the QEMU backend's launch flow: launch planning, the runtime lock and launch pid file, suspend-state persistence and resume validation, socket, QMP, and guest-agent readiness waits, guest file provisioning and write-back, the SSH session retry loop, managed process teardown, and launch timing stats.
Package launch contains the host-side building blocks shared by the QEMU backend's launch flow: launch planning, the runtime lock and launch pid file, suspend-state persistence and resume validation, socket, QMP, and guest-agent readiness waits, guest file provisioning and write-back, the SSH session retry loop, managed process teardown, and launch timing stats.
qemu/internal/qga
Package qga wraps the QEMU guest agent commands used by virtle.
Package qga wraps the QEMU guest agent commands used by virtle.
qemu/internal/qmpclient
Package qmpclient wraps the QEMU Machine Protocol commands used by virtle.
Package qmpclient wraps the QEMU Machine Protocol commands used by virtle.
qemu/internal/qmpwire
Package qmpwire shares line-delimited JSON socket helpers between the QMP and guest-agent clients, which speak the same wire framing over unix sockets.
Package qmpwire shares line-delimited JSON socket helpers between the QMP and guest-agent clients, which speak the same wire framing over unix sockets.
qemu/internal/runtime
Package runtime owns the live manager runtime exposed through the control socket.
Package runtime owns the live manager runtime exposed through the control socket.
qemu/internal/sessionbridge
Package sessionbridge carries CLI-only lifecycle hooks between the public QEMU backend and its foreground session package without adding them to the supported backend API.
Package sessionbridge carries CLI-only lifecycle hooks between the public QEMU backend and its foreground session package without adding them to the supported backend API.
qemu/internal/vmm
Package vmm is the qemu backend's VM machinery: the host-side launcher lifecycle behind backend/qemu and the virtle CLI.
Package vmm is the qemu backend's VM machinery: the host-side launcher lifecycle behind backend/qemu and the virtle CLI.
qemu/limits
Package limits defines the resource bounds enforced by the QEMU backend.
Package limits defines the resource bounds enforced by the QEMU backend.
qemu/session
Package session implements the virtle CLI foreground loop over the public backend machine contract.
Package session implements the virtle CLI foreground loop over the public backend machine contract.
internal
control
Package control implements virtle's local runtime control socket protocol.
Package control implements virtle's local runtime control socket protocol.
executor
Package executor renders exec command templates and manages external processes.
Package executor renders exec command templates and manages external processes.
executor/executortest
Package executortest provides test doubles for the executor package.
Package executortest provides test doubles for the executor package.
manifest
Package manifest defines the internal virtle launch contract.
Package manifest defines the internal virtle launch contract.
manifest/schema
Package schema generates the JSON Schema for the manifest input format.
Package schema generates the JSON Schema for the manifest input format.
manifest/tagged
Package tagged decodes and encodes JSON-style tagged union lists.
Package tagged decodes and encodes JSON-style tagged union lists.
readiness
Package readiness contains generic token-based readiness helpers.
Package readiness contains generic token-based readiness helpers.
sshtools
Package sshtools contains reusable SSH command helpers.
Package sshtools contains reusable SSH command helpers.
Package manifest loads virtle manifests (TOML or JSON) and lowers them to a neutral vm.Spec plus the backend they configure.
Package manifest loads virtle manifests (TOML or JSON) and lowers them to a neutral vm.Spec plus the backend they configure.
Package units defines small typed scalars shared across the virtle API, so sizes and durations are never plumbed around as bare ints.
Package units defines small typed scalars shared across the virtle API, so sizes and durations are never plumbed around as bare ints.
vm
Package vm holds the consumer-facing types for describing and controlling virtual machines: the neutral Spec a backend launches, and the Guest interface for operating inside a running VM.
Package vm holds the consumer-facing types for describing and controlling virtual machines: the neutral Spec a backend launches, and the Guest interface for operating inside a running VM.
vmtest
Package vmtest provides in-memory doubles for vm package contracts.
Package vmtest provides in-memory doubles for vm package contracts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL