The Embedded Playbook
sandbar provisions each VM's software with an Ansible playbook — the same
site.yml, roles/, ansible.cfg, and group_vars/ this repository has
carried since before its conversion to a Go CLI. That playbook is not a
separate tool you run: it is baked into the sandbar binary and driven
entirely by sandbar itself. This page documents the mechanism for
contributors who need to touch roles/ or site.yml. It is not a guide
to running Ansible by hand — nothing here should be read as an
instruction to install Ansible or invoke ansible-playbook; sandbar does
both, inside the guest, on your behalf.
The fileset is embedded in the binary
playbook_embed.go at the repository root go:embeds the whole fileset —
site.yml, ansible.cfg, inventory, roles/, and group_vars/ — into
the sandbar module as PlaybookFS. This is what lets a Homebrew-installed
sandbar provision without a repository checkout anywhere on disk: the
playbook travels inside the compiled binary.
How the playbook directory is resolved
At run time, provision.LocatePlaybook() (internal/provision/playbook.go)
picks the directory to mount into the VM in two tiers:
- Working tree first. It runs
git rev-parse --show-topleveland, if that succeeds and the resulting directory containssite.yml, uses it directly. - Embedded fallback. Otherwise — no git checkout, e.g. a
Homebrew-installed binary run outside any repository — it extracts
PlaybookFSto a fresh private temp directory and uses that.
This is the single most useful fact on this page for a contributor: if
you run go run ./cmd/sandbar from inside this checkout, your uncommitted
edits to roles/ or site.yml take effect on the very next provision.
There is no rebuild-and-reinstall step to remember.
How it reaches the guest, and what runs where
Ansible itself is installed inside the guest, not on the host, and the
playbook runs there with --connection=local — the host never executes
ansible-playbook at all. How the fileset gets into the guest depends on
the backend:
- On Lima (local or remote), the resolved directory is mounted into the guest as its only mount, and that mount is read-only.
- On Proxmox, there is no mount at all — there's no shared filesystem to
make one from.
sandbarpackages the fileset into a gzipped tar (buildPlaybookTar) and streams it to the guest over the SSH connection's stdin, where it's unpacked. Same fileset, no mount.
On Lima, the in-guest provisioning script (inGuestScript in
internal/provision/provision.go) rsyncs the mounted playbook fileset into
a guest-local working copy before each run, filtered to exactly the members
playbook_embed.go declares (site.yml, ansible.cfg, inventory,
roles/***, group_vars/***) — never the whole mount, which in
working-tree mode would otherwise be an entire git checkout. The Proxmox tar
is built from that same list, so both paths carry the same files and neither
can leak a checkout's .git or Go sources into a guest. Per-phase
extra-vars are streamed into the guest over stdin into /dev/shm (tmpfs)
and removed on exit; they are never placed on argv or written to the
persistent disk, so a clone token never appears in a process listing.
The three provisioning phases
site.yml's roles gate on a provision_phase variable
(internal/provision/vars.go sets it per run) that takes one of three
values:
| Phase | What runs | When |
|---|---|---|
base |
Shared setup: base, user, agent-clipboard, agent-cleanup, (conditionally) samba, dev-tools |
Building or maintaining the shared base before cloning; clipboard support is common to every agent and cleanup removes legacy agent installs |
finalize |
Per-VM setup: base, user, selected agent roles, agent-install, agent-context, project |
Against each clone; selected agents and their global context install here |
full |
Everything, in one pass | The default when the phase isn't otherwise specified |
This split is what lets sandbar build one expensive base image and clone it
cheaply for every subsequent VM, installing current agent releases alongside
identity-specific work against each clone.
Roles
roles/ contains base, user, agent-clipboard, agent-cleanup, samba, dev-tools,
mkcert-ca, claude-code, codex, opencode, pi, agent-install, agent-context,
self-review, and project.
site.yml runs them in that order, gated by
provision_phase as above. samba is worth calling out specifically:
internal/provision/vars.go sets samba_enabled: false on every sandbar
run (files move with limactl copy or scp instead of a Samba share),
so the role exists in the tree and is exercised by CI's syntax check, but it
does not execute on the sandbar path.
The four agent roles write configuration only. agent-install runs after
them, when at least one agent is selected, and starts every selected
installer at once as an Ansible async job, then waits on each under its own
task name (Install Claude Code using the official installer, and so on), so
finalize costs the slowest installer rather than all of them in turn. OpenCode
and Pi share one npm install, because two npm processes writing one prefix
are not safe. Running after the configuration roles is deliberate: nothing
Ansible manages edits ~/.bashrc or an agent's settings while an installer
runs, and Claude Code's create-only settings are seeded before claude
install can create them. Each wait gives up after agent_install_timeout
seconds (900 by default) rather than blocking forever.
agent-context runs after the selected agent roles, during full or
finalize only when at least one of Claude Code, Codex, Pi, or OpenCode is
selected. It adds a marked block to each selected agent's global instruction
file and installs one shared sandbar-environment skill at
~/.agents/skills/sandbar-environment, with a Claude symlink under
~/.claude/skills. The instruction files are ~/.claude/CLAUDE.md,
~/.codex/AGENTS.md, ~/.pi/agent/AGENTS.md, and
~/.config/opencode/AGENTS.md. One skill reference, this-vm.md, is a
template filled from sandbar_vm_name and sandbar_profile_type, which
BuildExtraVars emits for full and finalize: an agent cannot discover the
name host-side sandbar commands take, or which profile type decides how a guest
port is reached, from inside the guest. The role preserves other text, file modes, and
unrelated skills; it fails on a user-owned skill at either destination instead
of replacing it. It does not run for the base phase or a VM with no selected
agents. This is per-VM provisioning, not a background update of existing VMs
or a replacement for an agent's system prompt. The shared files under
roles/agent-context/files/ are embedded with the playbook.
CI coverage
The lint job in .github/workflows/test.yml runs
ansible-playbook -i localhost, --connection=local site.yml --syntax-check
on every push and pull request, so a syntax error anywhere in the playbook
fails CI fast — this is the one place in the pipeline where
ansible-playbook runs directly, and it exists purely to validate the
fileset that sandbar embeds.
inventory is vestigial
inventory still contains a single placeholder host
(ansible_host=CHANGE_ME), and it is part of the embedded fileset. It is a
holdover from before the Go conversion, when the playbook was run directly
against a real inventory. On the sandbar path it is unused: sandbar invokes
Ansible with -i localhost, inside the guest and never reads this file.
It stays in the tree because it is embedded and harmless, not because
anything on the sandbar path consults it.