Use Barn with an AI Agent
less than a minute
Barn publishes an agent skill, Barn VMs (barn): one Markdown file that teaches a coding agent to create, use, change, and clean up Barn VMs. It gives the agent Barn’s mental model, an index of this documentation, starting points for common scenarios (one Ubuntu machine, a multi-node lab, a Pigsty sandbox, replacing Vagrant, distribution matrices, CI, macOS VMs), and the boundaries it must respect. For command details, it sends the agent back to these pages.
Start with a prompt
Paste this prompt into the agent and replace the brackets with your requirements:
The last line carries the task, for example:
What I need: one VM to test the install script in ~/src/app.What I need: a four-node Pigsty sandbox from the full template in ~/pigsty.What I need: replace the Vagrantfile in this repository with a barn.yml that keeps the node names and IPs.What I need: a macOS VM named build with 8 CPUs and 16 GiB of memory, sharing ~/src.
Install the skill
To load the skill in every session, save it to the agent’s skill directory and start a new session:
Agents without a skill directory read the URL directly. Use skill.zh.md for the Chinese edition. Download the file again to update it; its header names the Barn version it matches.
What the agent asks first
Most Barn commands run as your user without prompts. The skill tells the agent to ask before it:
- changes an existing Linux lab, because each user has one deployment;
- prepares the host with
barn setup --yes, which installs packages, creates the private network, and usessudo; whensudoneeds a password, the agent gives you the command to run; - downloads a macOS restore image of about 24 GiB;
- runs
destroy,recreate, orpurge, or deletes VM disks in any other way.
When it finishes, the agent reports the nodes it created, how to connect, any warnings from barn up, the changes it made to the host, and how to stop or remove the VMs.