# Use Barn with an AI Agent

> Give Claude Code, Codex, or another coding agent the Barn skill so it can bring up Linux labs and macOS VMs for you.

---

LLMS index: [llms.txt](/llms.txt)

---

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.

- English: <https://barn.pgsty.com/skill.md>
- 简体中文：<https://barn.pgsty.com/skill.zh.md>

## Start with a prompt {#prompt}

Paste this prompt into the agent and replace the brackets with your requirements:

```text
Use Barn to run virtual machines on this computer, following the Barn skill: https://barn.pgsty.com/skill.md
Check commands and configuration against the Barn docs (https://barn.pgsty.com/docs/); use the default Ubuntu 24.04 unless I say otherwise.
What I need: [purpose, nodes and sizes, OS and architecture, working directory, Pigsty or not, macOS VMs…]
```

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 {#install}

To load the skill in every session, save it to the agent's skill directory and start a new session:

```bash {tab="Claude Code" group="agent-skill" value="claude"}
mkdir -p ~/.claude/skills/barn
curl -fsSL https://barn.pgsty.com/skill.md -o ~/.claude/skills/barn/SKILL.md
```

```bash {tab="Codex" group="agent-skill" value="codex"}
mkdir -p ~/.codex/skills/barn
curl -fsSL https://barn.pgsty.com/skill.md -o ~/.codex/skills/barn/SKILL.md
```

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 {#approvals}

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](/blog/design/one-deployment-no-projects/);
- prepares the host with `barn setup --yes`, which installs packages, creates the private network, and uses `sudo`; when `sudo` needs a password, the agent gives you the command to run;
- downloads a macOS restore image of about 24 GiB;
- runs `destroy`, `recreate`, or `purge`, 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.
