Skip to content

Build a software factory

Three issues become three pull requests. Each issue runs on its own fork of one base VM. Each agent pushes its branch, and the VM opens a pull request for it.

  • An approved account and an API key from the API keys page.
  • A GitHub fine-grained token with Contents and Pull requests set to read and write for the repository, as in Open pull requests.
  • Three open issues in that repository. This guide uses issues 101, 102 and 103.
  • Python 3.12 with requests, Node 22 for the TypeScript tab, or jq for the curl tab.

Set these once in your terminal.

Terminal window
export SI_API_KEY=si_...
export GH_PAT=github_pat_...

The VM never reads the token. The key vault adds it to GitHub requests on the way out. Store it as a secret named github.

Terminal window
curl -sS -X POST "https://api.slashinfra.com/secrets" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d "{\"name\":\"github\",\"value\":\"$GH_PAT\"}"
Output
{"id":"sec_6f1c0f0e8a","name":"github",...}

Set SECRET to the id in the reply. The secret answers with its name and id only, never its value.

Terminal window
export SECRET=sec_6f1c0f0e8a

Create the VM that the forks copy. Two rules send the token to GitHub: one for git over HTTPS, one for the GitHub API that gh calls. The GH_TOKEN variable holds a placeholder, so gh sends a header.

Terminal window
curl -sS -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d @- <<JSON
{"name":"factory-base","env":{"GH_TOKEN":"injected"},
"secret_injections":[
{"domain":"github.com","header":"authorization","value_format":"basic_x_access_token","secret_id":"$SECRET"},
{"domain":"api.github.com","header":"authorization","value_prefix":"Bearer ","secret_id":"$SECRET"}]}
JSON
Output
{"id":"6f1c0f0e8a","generation":1,...}

Set BASE to the id in the reply, then sign in to Claude Code in the base VM. Open its terminal from the dashboard, run claude, and complete the sign-in, as in Fix a failing test with Claude Code. Every fork copies that sign-in.

Terminal window
export BASE=6f1c0f0e8a

Start a job in the base VM that clones the repository. Then wait for it to end. The wait repeats while the reply has X-Timeout: 1, as in Background work.

Keep the two functions from this step in the same file. Step 4 uses them.

Terminal window
JOB=$(curl -sS -X POST "https://$BASE.slashinfra.dev/usr/bin/job?cwd=/home/user&arg=-q" \
-H "Authorization: Bearer $SI_API_KEY" \
--data-binary 'git clone https://github.com/your-org/your-repo.git /home/user/app')
while HEADERS=$(curl -sS -D - -o /dev/null -X POST "https://$BASE.slashinfra.dev/usr/bin/job?arg=wait&arg=$JOB" \
-H "Authorization: Bearer $SI_API_KEY"); grep -qi '^X-Timeout: 1' <<<"$HEADERS"; do :; done
grep -i '^X-Exit-Code' <<<"$HEADERS" | cut -d' ' -f2 | tr -d '\r'
Output
0

For each issue, fork the base VM, then start an agent that fixes the issue, pushes its branch and opens a pull request. The forks run at the same time. The output lists each fork’s id and the exit code of its job. A pull request step that fails leaves a non-zero code.

The forks carry the label run=factory, so step 5 finds them. --permission-mode bypassPermissions lets Claude Code edit files and run commands without asking. A job has no one to answer a prompt, and the agent works inside its own VM.

Terminal window
VMS=()
JOBS=()
for ISSUE in 101 102 103; do
VM_ID=$(curl -sS -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d "{\"name\":\"issue-$ISSUE\",\"fork_of\":\"$BASE\",\"labels\":{\"run\":\"factory\"}}" | jq -r .id)
JOB=$(curl -sS -X POST "https://$VM_ID.slashinfra.dev/usr/bin/job?cwd=/home/user&arg=-q" \
-H "Authorization: Bearer $SI_API_KEY" \
--data-binary "cd /home/user/app && git checkout -b issue-$ISSUE && claude -p --permission-mode bypassPermissions 'Read GitHub issue $ISSUE with gh issue view, fix it and commit the fix.' && git push -u origin issue-$ISSUE && gh pr create --head issue-$ISSUE --fill")
VMS+=("$VM_ID")
JOBS+=("$JOB")
done
for i in "${!VMS[@]}"; do
while HEADERS=$(curl -sS -D - -o /dev/null -X POST "https://${VMS[$i]}.slashinfra.dev/usr/bin/job?arg=wait&arg=${JOBS[$i]}" \
-H "Authorization: Bearer $SI_API_KEY"); grep -qi '^X-Timeout: 1' <<<"$HEADERS"; do :; done
echo "${VMS[$i]} $(grep -i '^X-Exit-Code' <<<"$HEADERS" | cut -d' ' -f2 | tr -d '\r')"
done
Output
6f1c0f0e8a 0
7h2d1g1f9b 0
8j3e2h2g0c 0

Delete the three forks, then the base VM, then the secret. The secret cannot be deleted while a VM still uses it.

Terminal window
for ID in $(curl -sS "https://api.slashinfra.com/svms?label.run=factory" -H "Authorization: Bearer $SI_API_KEY" | jq -r '.svms[].id'); do
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/svms/$ID" -H "Authorization: Bearer $SI_API_KEY"
done
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/svms/$BASE" -H "Authorization: Bearer $SI_API_KEY"
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://api.slashinfra.com/secrets/$SECRET" -H "Authorization: Bearer $SI_API_KEY"
Output
204
204
204
204
204

You should now see three open pull requests in your repository, one for each branch: issue-101, issue-102 and issue-103.

Symptom Cause Fix
A job exits with 1 and gh prints a 401 or 403 The token lacks write access to Contents or Pull requests. Create a token with both set to write, then replace the value with PUT /secrets/{ref}.
409 on a create A VM or a secret with that name exists. Delete the old one, then run the step again.
409 with secret_in_use in step 5 A VM still uses the secret. Delete the VMs first, then the secret.

Scroll horizontally to see all columns.