# Run agent evals

Run one prompt on a fresh fork of a base VM for each task, then print a pass or fail table from the tests of each fork.

Source: https://slashinfra.com/docs/build/agent-evals
Last modified: 2026-11-30T16:36:19.000Z

One prompt runs on a fresh fork for each task. Each fork starts from the same disk, runs the agent, then runs the repository’s tests. The output is a pass or fail table.

## Before you start

- An approved [account](https://app.slashinfra.com/) and an API key from the [API keys](https://app.slashinfra.com/keys) page. 
- A base VM with your repository in `/home/user/app`, its dependencies installed, and Claude Code signed in. Follow steps 1 and 2 of [Fix a failing test with Claude Code](https://slashinfra.com/docs/agents/claude-code), then clone the repository and install its dependencies in the same VM. 
- A test command, `npm test`, that exits with `0` when the repository passes. A fork passes when that command exits with `0`. 
- Python 3.12 with `requests`, Node 22 for the TypeScript tab, or `jq` for the curl tab.

Set these once in your terminal. The prompt must not contain a single quote, because the job wraps it in quotes.

```bash
export SI_API_KEY=si_...
export BASE=<base-vm-id>
export PROMPT='Fix the failing test in this repository. Do not change the tests.'
```

## 1. Fork a VM per task

Create one fork of the base VM for each task. Each fork is named `eval-1`, `eval-2` and so on, and carries the label `run=eval`. The label lets the next steps find the forks.

### curl

```bash
for NUMBER in 1 2 3; do
curl -sS -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d "{\"name\":\"eval-$NUMBER\",\"fork_of\":\"$BASE\",\"labels\":{\"run\":\"eval\"}}"
echo
done
```

### Python

```python
import os, requests

for number in [1, 2, 3]:
res = requests.post(
"https://api.slashinfra.com/svms",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
json={"name": f"eval-{number}", "fork_of": os.environ["BASE"], "labels": {"run": "eval"}},
)
res.raise_for_status()
print(res.text)
```

### TypeScript

```ts
for (const number of [1, 2, 3]) {
const res = await fetch('https://api.slashinfra.com/svms', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ name: `eval-${number}`, fork_of: process.env.BASE!, labels: { run: 'eval' } }),
})
if (!res.ok) throw new Error(`fork failed: ${res.status}`)
console.log(await res.text())
}
```

Output

```text
{"id":"6f1c0f0e8a","name":"eval-1","generation":1,...}
{"id":"7h2d1g1f9b","name":"eval-2","generation":1,...}
{"id":"8j3e2h2g0c","name":"eval-3","generation":1,...}
```

Each fork starts with the files of the base VM. Its writes stay in its own VM, so the forks do not see each other’s changes.

## 2. Run the prompt and the tests

In each fork, start a job that runs the agent and then `npm test`. The job’s exit code is the exit code of `npm test`, because the agent’s own exit code does not decide the result. The forks run at the same time. The table lists each fork and its result. `--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.

### curl

```bash
SCRIPT="cd /home/user/app && claude -p --permission-mode bypassPermissions '$PROMPT'; npm test"
LISTING=$(curl -sS "https://api.slashinfra.com/svms?label.run=eval" -H "Authorization: Bearer $SI_API_KEY")

echo "name    result  exit"
RUNS=$(jq -r '.svms[] | "\(.id) \(.name)"' <<<"$LISTING")
while read -r ID NAME; do
JOB=$(curl -sS -X POST "https://$ID.slashinfra.dev/usr/bin/job?cwd=/home/user&arg=-q" \
-H "Authorization: Bearer $SI_API_KEY" --data-binary "$SCRIPT")
while HEADERS=$(curl -sS -D - -o /dev/null -X POST "https://$ID.slashinfra.dev/usr/bin/job?arg=wait&arg=$JOB" \
-H "Authorization: Bearer $SI_API_KEY"); grep -qi '^X-Timeout: 1' <<<"$HEADERS"; do :; done
CODE=$(grep -i '^X-Exit-Code' <<<"$HEADERS" | cut -d' ' -f2 | tr -d '\r')
if [ "$CODE" = "0" ]; then RESULT=pass; else RESULT=fail; fi
printf '%-8s%-8s%s\n' "$NAME" "$RESULT" "$CODE"
done <<<"$RUNS"
```

### Python

```python
import os, requests

def start_job(vm_id: str, script: str, cwd: str) -> str:
res = requests.post(
f"https://{vm_id}.slashinfra.dev/usr/bin/job",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
params={"cwd": cwd, "arg": "-q"},
data=script.encode(),
)
res.raise_for_status()
return res.text.strip()

def wait_for_job(vm_id: str, job: str) -> int:
while True:
res = requests.post(
f"https://{vm_id}.slashinfra.dev/usr/bin/job",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
params=[("arg", "wait"), ("arg", job)],
)
res.raise_for_status()
if "X-Timeout" not in res.headers:
return int(res.headers["X-Exit-Code"])

listing = requests.get(
"https://api.slashinfra.com/svms",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
params={"label.run": "eval"},
)
listing.raise_for_status()

script = f"cd /home/user/app && claude -p --permission-mode bypassPermissions '{os.environ['PROMPT']}'; npm test"
runs = [(svm["name"], svm["id"], start_job(svm["id"], script, "/home/user")) for svm in listing.json()["svms"]]

print("name    result  exit")
for name, vm_id, job in runs:
code = wait_for_job(vm_id, job)
result = "pass" if code == 0 else "fail"
print(f"{name:<8}{result:<8}{code}")
```

### TypeScript

```ts
type Svm = { id: string; name: string }

const auth = { Authorization: `Bearer ${process.env.SI_API_KEY!}` }

async function startJob(vmId: string, script: string, cwd: string): Promise<string> {
const url = `https://${vmId}.slashinfra.dev/usr/bin/job?cwd=${encodeURIComponent(cwd)}&arg=-q`
const res = await fetch(url, { method: 'POST', headers: auth, body: script })
if (!res.ok) throw new Error(`job start failed: ${res.status}`)
return (await res.text()).trim()
}

async function waitForJob(vmId: string, job: string): Promise<number> {
const url = `https://${vmId}.slashinfra.dev/usr/bin/job?arg=wait&arg=${job}`
for (;;) {
const res = await fetch(url, { method: 'POST', headers: auth })
if (!res.ok) throw new Error(`wait failed: ${res.status}`)
if (!res.headers.has('X-Timeout')) return Number(res.headers.get('X-Exit-Code'))
}
}

const listing = await fetch('https://api.slashinfra.com/svms?label.run=eval', { headers: auth })
if (!listing.ok) throw new Error(`list failed: ${listing.status}`)
const { svms } = (await listing.json()) as { svms: Svm[] }

const script = `cd /home/user/app && claude -p --permission-mode bypassPermissions '${process.env.PROMPT!}'; npm test`
const runs: { fork: Svm; job: string }[] = []
for (const fork of svms) {
runs.push({ fork, job: await startJob(fork.id, script, '/home/user') })
}

console.log('name    result  exit')
for (const { fork, job } of runs) {
const code = await waitForJob(fork.id, job)
console.log(`${fork.name.padEnd(8)}${(code === 0 ? 'pass' : 'fail').padEnd(8)}${code}`)
}
```

Output

```text
name    result  exit
eval-1  pass    0
eval-2  fail    1
eval-3  pass    0
```

## 3. Clean up

Delete the forks. The base VM stays, so you can run the evals again. Delete it with [`DELETE /svms/{id}`](https://slashinfra.com/docs/api-reference/control/svms#deleteSvmsById) when you no longer need it.

### curl

```bash
for ID in $(curl -sS "https://api.slashinfra.com/svms?label.run=eval" -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
```

### Python

```python
import os, requests

auth = {"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}
listing = requests.get("https://api.slashinfra.com/svms", headers=auth, params={"label.run": "eval"})
listing.raise_for_status()
for svm in listing.json()["svms"]:
print(requests.delete(f"https://api.slashinfra.com/svms/{svm['id']}", headers=auth).status_code)
```

### TypeScript

```ts
const auth = { Authorization: `Bearer ${process.env.SI_API_KEY!}` }
const listing = await fetch('https://api.slashinfra.com/svms?label.run=eval', { headers: auth })
if (!listing.ok) throw new Error(`list failed: ${listing.status}`)
const { svms } = (await listing.json()) as { svms: { id: string }[] }

for (const svm of svms) {
const res = await fetch(`https://api.slashinfra.com/svms/${svm.id}`, { method: 'DELETE', headers: auth })
console.log(res.status)
}
```

Output

```text
204
204
204
```

> Caution
> 
> 
> 
> Deletes the forks and their files. The results stay only in the table you printed. Copy any file you want to keep before you delete the fork.

## Check it works

The table has one row for each fork, and each row shows `pass` or `fail` with the exit code of its `npm test`. To compare runs, delete the forks with step 3, then run steps 1 and 2 again and compare the two tables.

## If it doesn’t work

| Symptom | Cause | Fix |
| --- | --- | --- |   
| `409` on step 1 | A fork named `eval-1` already exists. | Run step 3, then step 1 again. | 
| Every row shows `fail` with `127` | `npm` or `claude` is missing from the path of the job. | Run `npm --version` and `claude --version` in the base VM. | 
| Every row fails at once | The prompt contains a single quote, which ends the quoted text in the job script. | Remove the quote from `PROMPT`, then run steps 1 and 2 again. |

## Next

- [Background work](https://slashinfra.com/docs/build/background-work): the jobs that run each fork, and the log of each job. 
- [Snapshots](https://slashinfra.com/docs/platform/snapshots): keep a base VM as a snapshot, so you can fork it later. 
- [Software factory](https://slashinfra.com/docs/build/software-factory): the same forks, each ending in a pull request.
