# Benchmarks

kosa8 Cloud offers SWE-bench Verified and Terminal-Bench as ready-made templates. Each instance's environment is its official image, pinned by digest, and kosa8 builds it the first time any organization uses it (or when you [prepare] it). Its grader is the benchmark's own: hidden tests, run in a sealed copy, reward 1 when the instance is resolved. You build and import nothing. Name an instance as a template to get a sandbox, or name the benchmark in a [hosted job](https://docs.kosa8.com/guides/cloud-jobs/) to run many.

## The benchmarks

| Name | Instances | Source | Graded by |
|---|---|---|---|
| `swe-bench-verified` | 500 | Hugging Face `SWE-bench/SWE-bench_Verified`, images `swebench/sweb.eval.x86_64.*` | The harness's eval script and the repository's log parser (swebench 5.0.2): FAIL_TO_PASS and PASS_TO_PASS must all pass |
| `terminal-bench-2.1` | 89 | `harbor-framework/terminal-bench-2-1`, the tasks' own prebuilt images | The task's `tests/test.sh`, its reward file |

`GET /v1/benchmarks` gives each benchmark's dataset revision and the date kosa8 read it. Terminal-Bench 4.x is newer, but its tasks build their images from a Dockerfile, some grade in a separate verifier image, and some need GPUs, so it is not offered yet.

## A sandbox of one instance

```
curl -s https://api.kosa8.com/v1/sandboxes -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d '{"template": "swe-bench-verified/django__django-11099"}'
# {"sandbox":{"id":"sbx_…","state":"running","template":"swe-bench-verified/django__django-11099",
#   "cpus":2,"mem_mb":4096,"source":"snapshot",…}}
```

The template is `<benchmark>/<instance id>`. The sandbox has the instance's code checked out (SWE-bench: `/testbed`; Terminal-Bench: the task's working directory) and its size. The hidden tests are not in it. `GET /v1/benchmarks/{name}/instances/{id}` gives the problem statement or instruction.

**The first use builds the environment.** Most instances are not built yet: on 22 November 2026, `GET /v1/benchmarks` showed `environments.ready` 3 of 500 for SWE-bench Verified and 4 of 89 for Terminal-Bench. Until an instance's environment is built, a create answers `409 template_building`. The answer is retryable and carries `eta_s`, `retry_after_s` and a `Retry-After` header:

```
{"error": "template_building", "template": "swe-bench-verified/django__django-11099",
 "state": "building", "eta_s": 240, "retry_after_s": 30, "retryable": true, "message": "…"}
```

**How long a build takes.** In our runs on 22 November 2026 a build took about 40 seconds (`django__django-11133` 37 s, `sympy__sympy-11618` 42 s, each about 4 GB). On a busy host it takes far longer: during a load test one build was still at phase `boot` after 7.8 minutes, against an `eta_s` of 30, and then failed. `eta_s` is an estimate, not a promise. kosa8 builds 4 environments at once, so a whole benchmark takes a while: the estimate for all 89 Terminal-Bench tasks put the build at `build_wall_s` 660 (11 minutes). A failed build answers **503** `template_build_failed` and is tried again after 30 minutes.

So build ahead of a run with `POST /v1/benchmarks/{name}/prepare` `{"instances": ["…"] | "all" | 50}` (up to 100 a call), and poll `GET /v1/benchmarks/{name}/instances/{id}` until its `environment.state` is `ready`:

```
curl -s -X POST https://api.kosa8.com/v1/benchmarks/swe-bench-verified/prepare \
  -H "Authorization: Bearer $KOSA8_API_KEY" -H 'Content-Type: application/json' \
  -d '{"instances": ["django__django-11133"]}'
# {"benchmark":"swe-bench-verified","instances":[{"id":"django__django-11133",
#   "template":"swe-bench-verified/django__django-11133","state":"building",
#   "phase":"starting","eta_s":30,…}],"builds_at_once":4}
curl -s https://api.kosa8.com/v1/benchmarks/swe-bench-verified/instances/django__django-11133 \
  -H "Authorization: Bearer $KOSA8_API_KEY"
# {"instance":{…,"environment":{"state":"ready","bytes":4295054419,…}}}
```

After the build, a create restores the environment in a few seconds (1.1 s and 4.4 s from create to running in our runs), for every organization. Building is kosa8's cost. A sandbox made from an environment counts toward your plan like any other.

## A whole benchmark as a job

```
POST /v1/jobs
{"name": "my-agent-v3",
 "benchmark": {"name": "swe-bench-verified", "instances": 50, "seed": 0},
 "solver": {"cmd": "python /workspace/agent.py", "files": {"/workspace/agent.py": "<base64>"}},
 "concurrency": 16, "budget_usd": 40}
```

`instances` is a list of ids, `"all"`, or `n` for a stable sample of n (set by `seed`). Leave out `template`, `tasks` and `grader`. The job builds the environments it needs first; its tasks wait while that happens. The solver takes one of three forms:

- **`{"cmd": …, "timeout_s"?, "env"?, "files"?}`**: your agent. It gets the input in `/workspace/.kosa8-task/input.json`, the problem in `problem.md` (SWE-bench) or `instruction.md` (Terminal-Bench) next to it, and `KOSA8_BENCHMARK`, `KOSA8_INSTANCE_ID` and `KOSA8_TASK_WORKDIR`. `timeout_s` defaults to the benchmark's agent time (SWE-bench 1 hour; Terminal-Bench the task's own).

- **`{"patches": {"django__django-11099": "diff --git …", …}}`** (SWE-bench): grade predictions you already have. A patch is applied the way the harness applies one (`git apply`, then `patch --fuzz`). `instances` defaults to the patches' ids.

- **`{"oracle": true}`**: the reference solutions. It checks the environments and should score about 1.

Each rollout's reward is 1 or 0. Its metrics include `fail_to_pass_passed`, `pass_to_pass_passed` and `patch_successfully_applied` (SWE-bench). The grader runs in the background, up to the benchmark's grading time (SWE-bench 30 minutes). When the environment is broken rather than the solution, the rollout is retried and then masked; it is never scored 0. Four Terminal-Bench tasks (`fix-ocaml-gc`, `pytorch-model-cli`, `sam-cell-seg`, `train-fasttext`) fetch files in their tests, so they are graded with the network. `GET /v1/benchmarks/{name}/instances/{id}` shows this as `grade_sealed: false`.

`POST /v1/jobs/estimate` with the same body gives the sandbox-hours, the cost, and `environments`: how many are ready, how many are still to build, and the build time (`build_wall_s`), plus `wall_s`, the job's own time range:

```
{"tasks": 50, "basis": "timeout", "size": "per instance",
 "per_task_s": {"low": 930, "high": 5430}, "sandbox_hours": {"low": 12.9, "high": 75.4},
 "usd_list": {"low": …, "high": …},
 "environments": {"ready": 0, "building": 0, "queued": 0, "failed": 0, "not_built": 50, "to_build": 50,
                  "build_s_each": 30, "builds_at_once": 4, "build_wall_s": 390},
 "wall_s": {"low": 3750, "high": 21750}, "note": "…"}
```

## CLI

**An API key is enough**

`kosa8 bench` and `kosa8 job` run on kosa8 Cloud, so they use your organization's plan through your API key: `KOSA8_API_KEY`, `kosa8 cloud login` or the browser sign-in, `kosa8 login`. This needs CLI v0.21.0 or later. Older versions asked for a plan on this machine even on a paid plan; there, use the HTTP API or the Python SDK's `cloud.jobs`, which work with the key.

```
kosa8 bench ls
kosa8 bench instances swe-bench-verified --state ready
kosa8 bench show swe-bench-verified/django__django-11099 --input
kosa8 bench prepare swe-bench-verified 50
kosa8 cloud sandbox create --template swe-bench-verified/django__django-11099

kosa8 job submit --benchmark swe-bench-verified --instances 50 \
  --solver "python /workspace/agent.py" --solver-file agent.py:/workspace/agent.py --watch
kosa8 job submit --benchmark swe-bench-verified --patches preds.jsonl     # {instance_id, model_patch} lines
kosa8 job submit --benchmark terminal-bench-2.1 --instances all --oracle --estimate
```

## The environment cache

Built environments are kept on kosa8's hosts, in a cache of 100 GB (`cache.budget_gb` in `GET /v1/benchmarks`). When a new build needs room, the environments used least recently (and idle for at least 15 minutes) are dropped, and the next use builds them again. kosa8 keeps only a small sample of each benchmark built at all times, so `prepare` the instances you need before each run.

## See also

- [Hosted jobs](https://docs.kosa8.com/guides/cloud-jobs/): retries, budgets and the job's RL run.

- [RL training](https://docs.kosa8.com/guides/rl-training/): runs, failure classes, the sealed grader.

---
Source: https://docs.kosa8.com/guides/benchmarks/
