Coding agents
Run agents in parallel
Give each coding agent its own flockvm VM, create them with the CLI, fan tasks out over SSH, collect the branches, pick the best of N, and clean up.
Two agents in one checkout overwrite each other's files, fight over port 3000 and migrate the same database. One VM per agent removes all of that: each one gets its own files, ports, database and Docker daemon. This page shows how to set up several VMs, start one agent in each over SSH, and bring the results back.
When one VM per agent pays off
| Setup | Good for | What breaks first |
|---|---|---|
| Git worktrees + tmux on your laptop | 2 to 4 agents on code that needs no server or database | Ports, the shared database, RAM |
| One flockvm VM per agent | Agents that start servers, run migrations or Docker, or run without permission prompts | Your review time, and the host's room |
The trade-offs for each agent count are in running Claude Code agents in parallel. A VM does not change your model plan's usage limits: N agents use quota about N times as fast.
Create the VMs
Name them after the task
Names take lowercase letters, digits and dashes, up to 40 characters. Use one prefix per task and a number per attempt, so the VM list reads like a batch:
fix-auth-1,fix-auth-2,fix-auth-3.Create each VM
With the CLI, one command per agent: same size, the Agent image (the default), your saved SSH key, a different name.
On your laptopfor i in 1 2 3; do flockvm vm create "fix-auth-$i" --size small --wait doneIn the dashboard, it is New VM once per agent, with the same choices. The API does the same from your own code.
If a size does not fit the host right now, the VM is refused with
409 capacity(the form says so too): pick a smaller size. See Limits.Write down the ports
Each VM has its own SSH port. Write them into a file, one VM per line:
On your laptopflockvm vm list --json \ | jq -r '.vms[] | select(.name | startswith("fix-auth-")) | "\(.name) \(.ssh.port)"' \ | sort > vms.txtvms.txtfix-auth-1 22001 fix-auth-2 22002 fix-auth-3 22003Without the CLI, copy the ports from the SSH command of each VM in your VM list.
Each row shows the VM's state and its SSH command.
Optionally, add the VMs to your SSH config so you can type ssh fix-auth-1 (User agent on Minimal VMs):
Host fix-auth-*
HostName HOST
User user
Host fix-auth-1
Port 22001
Host fix-auth-2
Port 22002
Host fix-auth-3
Port 22003Prepare every VM in one loop
On the Agent image, Claude Code and Codex are already installed, and you log in as user. Two credentials go into each VM: the agent's sign-in, and a key to clone and push. Create both once, on your laptop:
claude.env, a file with one line,export ANTHROPIC_API_KEY=…, with your organization's Claude Console key (or turn on Agent credentials and skip this file). With a Claude plan instead, leave the file empty, and after the loop below sign each VM in from inside it:ssh -t -p 22001 user@HOST claude, then/login, then/exit. Never copy a plan token into a VM. See Sign Claude Code in.- A deploy key for the repository, separate from your personal key:
ssh-keygen -t ed25519 -N '' -f ~/.ssh/flockvm-deploy, then add~/.ssh/flockvm-deploy.pubunder Settings → Deploy keys on GitHub, with write access.
Then copy them to every VM, trust GitHub's host key and clone the repository:
while read -r name port; do
echo "== $name"
scp -q -P "$port" claude.env user@HOST:.claude.env < /dev/null
scp -q -P "$port" ~/.ssh/flockvm-deploy user@HOST:.ssh/id_ed25519 < /dev/null
ssh -n -p "$port" user@HOST '
chmod 600 ~/.claude.env ~/.ssh/id_ed25519
grep -q claude.env ~/.bashrc || echo ". ~/.claude.env" >> ~/.bashrc
ssh-keyscan -t ed25519 github.com 2>/dev/null >> ~/.ssh/known_hosts
[ -d repo ] || git clone -q git@github.com:your-org/your-repo.git repo'
done < vms.txtssh -n and < /dev/null keep ssh and scp from reading the rest of vms.txt as their input.
On Minimal VMs: create the agent user and install Claude Code first
The Minimal image has no agent CLI and you log in as root. Run this script as root on each VM before the loop above, and use agent@HOST instead of user@HOST everywhere on this page. Adapt the install line for Codex.
#!/bin/bash
# Runs as root inside a fresh Minimal VM.
set -euo pipefail
id agent >/dev/null 2>&1 || useradd -m -s /bin/bash agent
install -d -m 700 -o agent -g agent /home/agent/.ssh
install -m 600 -o agent -g agent /root/.ssh/authorized_keys /home/agent/.ssh/authorized_keys
usermod -aG docker agent
npm install -g @anthropic-ai/claude-code >/dev/nullwhile read -r name port; do
ssh -p "$port" root@HOST 'bash -s' < setup-vm.sh
done < vms.txtHere ssh reads the script as its input, so it does not read vms.txt.
Fan out the task
Put the task in a file, and a small script that starts the agent in a detached tmux session on its own branch:
Fix the session expiry bug in src/auth (users are logged out after 5 minutes).
Add a test that reproduces it. Run the whole test suite. Commit your work.#!/bin/bash
# Usage: run-agent.sh BRANCH. Runs as user inside the VM.
set -euo pipefail
. ~/.claude.env
cd ~/repo
git switch -q -c "$1"
tmux new -d -s agent "claude -p --dangerously-skip-permissions \"\$(cat ~/task.md)\" 2>&1 | tee ~/agent.log"Start every agent:
while read -r name port; do
scp -q -P "$port" task.md run-agent.sh user@HOST: < /dev/null
ssh -n -p "$port" user@HOST "bash ~/run-agent.sh agent/$name"
echo "started $name"
done < vms.txtThe agents keep working after the loop ends and after you close your laptop. To watch one, attach to its session: ssh -t -p 22002 user@HOST tmux attach -t agent. More on sessions and logs in Long-running sessions.
Different tasks, same loop
For a backlog instead of N attempts at one task, give each VM its own task file: scp task-$name.md …:task.md.
Check progress
while read -r name port; do
state=$(ssh -n -p "$port" user@HOST 'tmux has-session -t agent 2>/dev/null && echo running || echo done')
echo "$name: $state"
done < vms.txtCollect the results
Each agent works on its own branch. Push them all, then review them as pull requests or locally:
while read -r name port; do
ssh -n -p "$port" user@HOST 'cd ~/repo && git push -q -u origin HEAD'
done < vms.txt
git fetch origin 'refs/heads/agent/*:refs/remotes/origin/agent/*'
git branch -r --list 'origin/agent/*'For files outside Git, such as logs, reports or build output, copy them back:
mkdir -p results
while read -r name port; do
scp -q -P "$port" user@HOST:agent.log "results/$name.log" < /dev/null
rsync -az -e "ssh -p $port" "user@HOST:repo/coverage/" "results/$name-coverage/" < /dev/null
done < vms.txtPick the best of N
When N agents try the same task, let the tests make the first pass. Run the suite in every VM and list which attempts pass, with the size of each diff:
while read -r name port; do
result=$(ssh -n -p "$port" user@HOST '
cd ~/repo
if npm test >/dev/null 2>&1; then t=pass; else t=fail; fi
echo "$t $(git diff --shortstat main...HEAD)"')
echo "$name: $result"
done < vms.txtReview the passing attempts first, smallest diff first, and merge one. How much best-of-N helps, and how to score attempts, is in best-of-N for coding agents.
What it costs
VMs bill per second while they start and run, and not while paused or stopped, for now.
| Batch | Size | Time | VM cost |
|---|---|---|---|
| 3 attempts at one task | small ($0.016/h) |
30 min each | 3 × 0.5 h × $0.016 = $0.024 |
| 5 tasks from a backlog | default ($0.032/h) |
45 min each | 5 × 0.75 h × $0.032 = $0.12 |
| 4 attempts, then 1 kept for review for a day, paused | default |
1 h each | 4 × 1 h × $0.032 = $0.128, $0 while paused |
Model tokens are billed separately by your provider, and grow with N. Your organization's spend shows on the Usage page.
Clean up
Keep the VM you are still reviewing
Click Pause on it. Its memory, processes and files stay, and billing stops.
Delete the others
On each VM page, click Delete, then Delete for good. The disk and a paused VM's saved memory go too, along with the credentials you copied in. Push anything you want to keep first.
Revoke the credentials
Delete the deploy key on GitHub, and revoke the Claude token or API key if the agents ran code you don't trust.
With the CLI, pause or delete the whole batch at once:
flockvm vm pause fix-auth-2
flockvm vm list --json \
| jq -r '.vms[] | select(.name | startswith("fix-auth-") and . != "fix-auth-2") | .name' \
| while read -r name; do flockvm vm delete "$name" --yes; doneThen remove the Host fix-auth-* entries from ~/.ssh/config, and the old host keys from ~/.ssh/known_hosts (ssh-keygen -R "[HOST]:22001"): the next VM that gets the same port has a new host key.
Let an agent run the batch
With the MCP server, an orchestrating agent such as Claude Code on your laptop can create the VMs itself (create_vm), read their SSH commands (get_vm), and pause or delete them when the attempts are reviewed. Give it a dedicated API key with an expiry and the Create and use VMs preset: it can create billed VMs, and delete only the ones it created. See MCP security.
Next steps
What breaks when agents share a machine, and what 5, 10 and 20 agents cost.
The single-VM setup, step by step.
tmux, logging and pause/resume.
Prices per size, per second.