The Manual

Sandboxes

nixarchy vm create shell-1 and, seconds later, nixarchy vm run shell-1 puts you at a prompt inside a fresh NixOS — no root, no nixos-rebuild, and nothing left on the machine when you nixarchy vm rm it. Try a package set you do not trust, run a build that wants root, check whether a config actually boots, reproduce someone’s bug report: today, off this feature, each of those either happens on your real machine or does not happen.

It is microvm.nix underneath, booted with your host’s /nix/store mounted read-only over 9p rather than copied into a disk image — a sandbox costs megabytes, not gigabytes, and the packages inside it are the same store paths as the ones outside it.

The MicroVMs panel running demo-shell: the guest's closure copied and built, streaming into the panel until it reports the VM running in the background

What it is not

Not a desktop VM. Headless, no display. If you want a GUI machine with a window and a disk you manage, virt-manager from the catalogue is the tool for that — this is a console, and the console is the whole interface.

Not a container. A sandbox boots its own kernel, which is slower to start than podman run and is the entire point: a kernel parameter, a boot sequence, a module that wants CAP_SYS_ADMIN — none of that is answerable inside a container, on this machine or anywhere else.

Not a security boundary you should design a threat model around. The shared folder is your own home directory’s worth of state — a share/ directory inside each VM’s own, and the guest can write everything under /mnt/host — and KVM escapes exist. Isolation from a package you do not trust yet; not isolation from an attacker who already has a foothold in the guest.

Not nixarchy’s own test VM. nix run .#vm boots the desktop itself, to test this repository. A sandbox is a machine for you, running whatever template you picked, and the two share nothing but qemu.

Turning it on

nixarchy vm is a command, not a service — it is installed on every nixarchy machine, the same as nixarchy dev init, so there is nothing to enable for the disposable half above. What you are turning on by using it is whatever templates you pick, one machine at a time, and nothing runs until you do.

Nixarchy ▸ Sandbox opens the MicroVMs panel, on by default (Super+Alt+V on a new install): disposable VMs from nixarchy vm and the permanent machines you declare, in one list. Create, run in the background, attach to the console, stop and remove from there. See nixarchy’s plugins. If you turn the panel off in Setup → Plugins, the same row opens nixarchy vm list in a terminal instead, and programs.nixarchy.defaultPlugins.microvm = false stops nixarchy installing it.

The menu row is the one thing that needs a moment: Nixarchy ▸ Sandbox is generated into the merged menu defaults at rebuild time, and Omarchy’s shell reads that file once, at login. Rebuilding with this feature already on your system does not make the row appear in an already-open session — log out and back in, or omarchy menu summon vm from a terminal to skip the mouse. Search also finds it by alias: type “vm”, “sandbox” or “microvm” from the root of the menu.

The templates

nixarchy vm templates lists these from the running system; the table below is the same catalogue, data/microvm-templates.nix.

template what it adds note
shell nothing beyond the base guest the fastest way to a throwaway prompt, and the template every other one starts from
python python3, uv, 3 GiB RAM ephemeral — uv venv /mnt/host/.venv if the venv should outlive the VM
podman rootless-capable podman, Docker-compatible /var/lib/containers is a 20 GiB volume that survives a restart; the rest of the root filesystem does not
agent shell plus git, curl, and an egress allowlist nothing in the guest reaches the network except through a local proxy that only permits hosts you name — see Running an agent that cannot phone home
persistent shell plus /home on its own volume the volume goes when the VM does; the root filesystem is still thrown away every boot
node nodejs (LTS), pnpm, 3 GiB RAM ephemeral — pnpm install inside /mnt/host if node_modules should outlive the VM
agent-claude agent plus codex and opencode, with the model endpoints and GitHub pre-allowed claude-code only when unfree is allowed — NIXPKGS_ALLOW_UNFREE=1 nixarchy vm run <name>, or allowUnfree on a permanent machine; never in the public cache
k3s single-node k3s server, 4 GiB RAM, 2 vCPU /var/lib/rancher is a 20 GiB volume, so the cluster and its generated token survive a restart; traefik and servicelb off; kubectl inside the guest only
hyprland a Wayland compositor with grim, tesseract, wtype and an accessibility-forced Chromium, on one 1920x1080 virtual monitor for testing desktop tooling without a real session. No omarchy shell — this is plain NixOS. The first template that asks for a GPU, and the largest: about 5.2 GiB to realise, so the first run is a long one. The guest renders in software (no host GPU is behind its virtio GPU, #1506), so WebGL and other GL-heavy apps are slow. The compositor is a user service under start-hyprland, which exits 0 even when Hyprland fails — journalctl --user -u hyprland from the ttyS0 console if a capture comes back empty
hyprland-ai-mirror hyprland plus ai-mirror, listening on vsock port 7000 an MCP agent on the host drives this desktop instead of yours. Control is granted without asking — starting the VM is the consent. Each VM picks its own vsock CID, so several can run at once. The first grant after a cold boot takes up to ~20 s, while Hyprland starts. Its ai-mirror still words things as “your real desktop” and “human-confirmed”
nixarchy-desktop the stock nixarchy desktop for dev, plus ai-mirror on vsock port 7000 an MCP agent drives nixarchy itself: its keybindings, bar and omarchy-* commands. Control is granted without asking — starting the VM is the consent. 8 GiB of RAM, 4 vCPUs, software rendering, a 1280x800 monitor. The largest template (17.7 GiB closure, most of it already in the store of a nixarchy host on the same revision), and its vsock port opens only after omarchy’s first run, about 45 s after a cold boot under KVM (longer under TCG); a client that connects earlier fails, so connect after that. Notifications start on do-not-disturb. Its ai-mirror still words things as “your real desktop” and “human-confirmed”

Every template but one is a plain NixOS module — nothing there invents nixarchy vocabulary. If you outgrow one, copy module out of the catalogue entry into a flake of your own and grow it from the NixOS manual and microvm.nix’s own options reference from there. The exception is nixarchy-desktop, which is nixarchy itself: outgrow that one from the flake the installer generates.

Driving one with ai-mirror

Your real desktop and the sandbox are two MCP servers with the same tools. Add the sandbox next to the one you already have:

claude mcp add ai-mirror-<name> -- socat - VSOCK-CONNECT:$(cat ~/.local/state/nixarchy/microvm/<name>/vsock-cid):7000

Run it after the VM’s first start, which is when it picks its vsock CID and writes it to that file. A declared machine keeps it in /var/lib/microvms/<name>/vsock-cid. The CID never changes after that, so a VM you delete and create again under the same name gets a new one: add the server again. If two VMs ever share a CID (a copied VM directory does), qemu refuses to start the second. Delete its vsock-cid and it picks a new one.

Inside the guest, control is granted without asking: starting the VM is the consent. Your real desktop still asks every time. Stopping the VM is the kill switch. Several can run at once, each on its own CID.

nixarchy-desktop gives the agent nixarchy’s own keybindings, bar and omarchy-* commands, so ai-mirror index there describes nixarchy rather than a bare compositor.

Any local user on the host can reach its port, and whoever connects is granted control: that is dev in the guest, with passwordless sudo, the VM’s share/ folder and its outbound network. On a single-user desktop that is you; on a shared machine, do not run it. The first grant after a cold boot takes up to ~20 s, while Hyprland starts.

What is inside

Every guest, regardless of template, gets the same four things from modules/microvm/guest.nix:

Sharing a folder

Share a worktree when you create a disposable VM:

nixarchy vm create test-worktree --share "$(pwd -P):/work"
nixarchy vm run test-worktree

Repeat --share HOST:GUEST[:ro|:rw] for up to four folders. The default is ro. The guest can write in /work through an overlay in memory. The host files stay intact, and guest writes vanish at shutdown. Use :rw only for a worktree the guest may change on the host. Use /mnt/host for small hand-offs through the VM’s staging directory. If one folder fails to mount, the guest still boots and mounts the others. Check mountpoint /work and journalctl -u nixarchy-work-mounts in the guest.

The entire home directory is refused. Shares also cannot overlap the owner’s ~/.ssh, ~/.gnupg, ~/.config/op, ~/.password-store, /etc/ssh, /run/agenix, /root, or the VM state directory. An ordinary worktree such as ~/src/project can be shared. The guest can read files you share even when the host copy is read-only.

The guest path must be absolute, use only letters, digits, ., _, - and /, and contain no ... It may not be, sit inside, or contain /nix, /mnt/host, /mnt/.work, /mnt/.share, /proc, /sys, /dev, /run or /etc. A running VM has one virtiofsd per slot, all four, even when fewer folders are shared: the unused slots serve an empty folder.

Giving one disposable VM a credential

After creating the VM, import a value under the environment variable name your workload expects. Choose one source per import. These examples all set the same name on a VM called test-worktree:

nixarchy vm secret import test-worktree API_TOKEN --stdin < /private/path/to/token
nixarchy vm secret import test-worktree API_TOKEN --op 'op://Development/Test/token'
nixarchy vm secret import test-worktree API_TOKEN --agenix /run/agenix/test-token
nixarchy vm secret list test-worktree

Stdin preserves bytes through EOF, including trailing newlines and empty values. NUL is refused. The host administrator can grant provider access with programs.nixarchy.services.microvm.secretProviders. For 1Password, set opExecutable to the trusted CLI and list exact field references in opFields under the account that holds them. For agenix, set agenixRoots to the permitted runtime directories and give the caller read access to the specific file. Keep values out of the flake and ordinary shares.

Launch with nixarchy vm run test-worktree. Inside the guest, dev can read the snapshot at /run/nixarchy-secrets. Run nixarchy-secrets-shell to start a shell with those values in its environment. For one workload, use nixarchy-secrets-shell -c 'exec my-tool'.

Importing a replacement or running nixarchy vm secret clear test-worktree changes the next launch. The running guest keeps its read-only snapshot. If a prebuilt runner lacks the secrets mount, a configured VM needs a rebuilt runner before it can launch. Removing a stopped VM with nixarchy vm rm test-worktree deletes its private credential state.

Use short-lived credentials scoped to the task. A workload can copy a credential, and sufficiently privileged guest processes can inspect its environment. Clearing the VM cannot revoke a copy. Revoke it at the provider if needed.

Running an agent that cannot phone home

The agent template exists for one job: running an AI coding agent — or any program you are willing to let loose on a checkout but not on your network — where the filesystem boundary is not the only boundary.

The filesystem half is the same one every template gets, and it is the strong half: the guest sees your host /nix/store read-only, its staging directory at /mnt/host, and any folders you explicitly share. Those folders are read-only on the host by default.

What agent adds is the network. Every other template inherits “NAT out, nothing in”, which is no constraint at all on a process you are running because you do not fully trust it. Here, the guest’s own firewall drops everything outbound except the local proxy’s traffic, and the proxy refuses any host you did not name.

You name them one per line in the VM’s host-side policy/ directory before you start it. The guest sees this directory read-only at /mnt/agent-policy:

nixarchy vm create review-bot --template agent
cat > ~/.local/state/nixarchy/microvm/review-bot/policy/allow-hosts <<'EOF'
api.anthropic.com
github.com
EOF
nixarchy vm run review-bot

Subdomains of a listed host are allowed (github.com covers api.github.com), nothing else is, and # starts a comment. Inside the guest, http_proxy and https_proxy are already set, so curl, git, pip, uv, npm and every model SDK route through the proxy without being told.

No file, or an empty one, adds no hosts. The agent template then denies all destinations. agent-claude still allows its built-in model and GitHub hosts. If your agent cannot reach its own API, check the policy path first.

What this does and does not contain

It does stop a process in the guest from reaching anything but the hosts you listed. Not by asking it politely — there is no socket to the outside world for any user but the proxy’s, DNS included, so an agent cannot resolve a name, let alone open a connection. DNS tunnelling is off the table for the same reason.

It does not:

And when it does get out and break something

Worth saying once, because nobody markets it and it is free: on a NixOS machine an agent’s damage to the system is undone by

sudo nixos-rebuild --rollback switch

or by picking the previous generation in the boot menu. Whatever it added, removed or reconfigured through the system’s own configuration is gone, in one command, atomically. That is not a sandbox — it does not touch your home directory, your git working tree, or anything installed imperatively — but it is the reason “let an agent edit my configuration” is a much smaller bet here than on a distribution where it is not reversible.

Getting back in, stopping, destroying

nixarchy vm list                  # what you have, and which are running
nixarchy vm run shell-1           # attach again — Ctrl-A X leaves the
                                   # console without stopping the VM
nixarchy vm stop shell-1          # ask it to shut down
nixarchy vm rm shell-1            # delete it and its state

A second run of a name that is already attached refuses rather than racing a second qemu over the same shared directory — you get “already running”, not a wedged guest.

In the background, and back in later

nixarchy vm run --detach shell-1  # build here, then run it with no terminal
nixarchy vm console shell-1       # attach — Ctrl-] leaves it running
nixarchy vm set-template shell-1 python   # a stopped VM, rebuilt next run

--detach builds in front of you, so a build error is yours to read. Then a user unit, nixarchy-vm-<name>, owns the guest, and the command returns once the guest holds its lock. If it never does, the command says so and names journalctl --user -u nixarchy-vm-<name>. Ctrl-A X still stops the guest from its console.

set-template refuses while the VM runs, and refuses if the VM has volume images (*.img) the old template made — a k3s disk under a node VM helps nobody. Pass --keep-volumes to switch anyway.

For scripts: --json

nixarchy vm list --json includes name, template, running, dir, and shares. Each share reports its host, guest, and mode. A VM with no extra folders reports shares: [].

nixarchy vm templates --json prints [{"name", "label", "note"}]. The text output is unchanged. Fields are only ever added, never renamed or removed: the nixarchy.microvm panel reads these.

On-disk layout, and the GC root

Everything a VM has lives at ~/.local/state/nixarchy/microvm/<name>/: the template it was created from, share/ (guest-writable at /mnt/host: its runtime hostname and work files), policy/ (read-only to agent guests at /mnt/agent-policy, holding allow-hosts), and — after the first run — current, a symlink into the store that is also this VM’s garbage-collection root. nix build --out-link is what writes it, deliberately never nix run, which registers no root at all: a nix-collect-garbage while a guest is running would take the store it is 9p-mounted on out from under it.

Upgrading from before #1076

Guests used to see this whole directory, current included. That was a way from a guest to your host, as you or as root. They now see share/ only. Nothing was moved or deleted: files a guest wrote before are still one level up, and the guest no longer sees them. Move work files into share/. Recreate any VM that ran untrusted code before this change: it could already have replaced current or planted a symlink somewhere in its directory, and neither is undone by upgrading.

Upgrading from before #1100

An old share/allow-hosts is ignored. Inspect it and copy only the entries you still want into policy/allow-hosts on the host; the command and guest journal warn if the old file exists. It is never copied automatically because the guest could have edited it. An agent VM with no policy file reaches nothing beyond any closure-side defaults. Declarative machines use /var/lib/microvms/<name>/policy/allow-hosts; ordinary host users need root to maintain it.

The consequence worth knowing: a template dropped from a later release of this flake keeps running here, for any VM that already built its current link, until you rm that VM’s directory. There is no separate cleanup step and no image left behind once you do — rm -rf on the directory is the entire teardown, root included.

Upgrading: shares are now read-only

Each entry in machines.<name>.shares now uses virtiofs and defaults to readOnly = true. Guest writes to those shares are temporary. Set readOnly = false on a share if the guest must write through to the host. Existing host files are kept. Use an absolute directory path outside the MicroVM state directory. Guest paths use letters, digits, dots, underscores, hyphens and slashes. The mount service refuses the same reserved guest paths as --share: /nix, /mnt/host, /mnt/.work, /mnt/.share, /proc, /sys, /dev, /run, /etc, and any parent of one.

If a guest service uses a share, change its ordering. The folder at your mountPoint is an overlay or bind mount made by nixarchy-work-mounts.service. It has no NixOS mount unit of its own, so RequiresMountsFor = [ "/work" ] alone no longer waits for it: the service can start early and write underneath, and the mount then hides those files. In the machine’s modules, require the mount service and check each path.

programs.nixarchy.services.microvm.machines.build-box.modules = [
  {
    systemd.services.my-build = {
      requires = [ "nixarchy-work-mounts.service" ];
      after = [ "nixarchy-work-mounts.service" ];
      unitConfig.AssertPathIsMountPoint = [ "/work" ];
    };
  }
];

Keep any existing mount requirements for parent storage. The mount service can succeed with an individual share missing. List each required share in AssertPathIsMountPoint so systemd checks it before setting up the consumer’s private mount namespace or running its start commands. If a share is missing, systemd refuses to start my-build. Read journalctl -u nixarchy-work-mounts in the guest, fix the share, rebuild, and restart the machine. Restarting the mount service by itself can stack a second layer over mounted shares.

The declarative half

Everything above is the machine you create and destroy on a whim. For one you want to keep — up at every boot, without you starting it — programs.nixarchy.services.microvm is the other half of this feature, off by default:

programs.nixarchy.services.microvm = {
  enable = true;
  machines.build-box = {
    template = "podman";
    memory = 4096;
    cores = 2;
    sshPort = 2222;
  };
};

For a declarative machine, machines.<name>.memory defaults to null. Leave it unset to use its template’s RAM setting (agent uses 2560 MiB), or 1024 MiB for a template without one. Disposable VMs keep microvm.nix’s 512 MiB default when their template does not set memory. An explicit machines.<name>.memory uses mkForce and overrides microvm.mem even in machines.<name>.modules.

A declarative machine gets a forwarded SSH port compiled into its own closure — the one door the disposable half deliberately does not have, since every disposable VM of a template shares one closure and so cannot each carry a different port. State lives under /var/lib/microvms/<name>, root’s to manage, and the machine comes up under systemd the moment you rebuild. Turning this on for the first time also grants the kvm group to programs.nixarchy.user (or whoever programs.nixarchy.services.microvm.user names) and switches on microvm.host.enable upstream — both stay off, and nothing about a machine you have not declared runs, until machines, or a microvm.vms of your own, is non-empty. If you run only imperative microvm -c machines, set microvm.host.enable = true yourself.

See also: Per-project environments for the other “an environment vs. a machine” tool on this desktop — devenv answers “I want this directory’s toolchain,” a sandbox answers “I want a machine.”