> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vers.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Vers with AI agents

> Let Claude Code, Codex, or custom agent loops boot, operate, and branch isolated KVM microVMs via ssh try.vers.sh, /llms.txt, or /api/v2.

Vers is built for long-running coding, QA, SRE, and evaluation agents that need
a real Linux computer they can mutate, checkpoint, branch in parallel, and put
to sleep between turns.

## Zero-signup trial with your coding agent (`/llms.txt`)

You can test Vers inside Claude Code, Codex, Cursor, or any terminal-capable
coding agent in under a minute without creating an account or minting an API key:

1. Point your agent at [`https://vers.sh/llms.txt`](https://vers.sh/llms.txt).
2. Let it run commands against `ssh try.vers.sh` — any unrecognized SSH key
   automatically provisions an expiring KVM trial, and `scp`, `sftp`, and
   `ssh -L` port forwarding work out of the box.

Example prompt to paste into your coding agent:

```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
Read https://vers.sh/llms.txt and use `ssh try.vers.sh` to boot an ubuntu:24.04
computer, verify the kernel with `uname -a`, and run a quick script inside it.
```

Try the underlying command yourself directly from your terminal:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
ssh try.vers.sh run ubuntu:24.04 -- uname -a
```

When you are ready to keep your computers and branches beyond the trial window,
upgrade the same SSH identity in place:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
ssh try.vers.sh upgrade
```

## Canonical production agent loop (warm once → branch N → pick winner)

For custom agent harnesses, SWE-bench/eval runners, and autonomous QA pipelines,
avoid paying a 30–180 second repo build or database seed on every attempt:

```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
1. Boot one base computer (or multi-VM project stack) from your OCI image
2. Clone the repo, install dependencies, and run baseline setup once
3. Capture a full-state checkpoint (POST /api/v2/computers/{id}/checkpoints)
4. Fan out N isolated branches in parallel (POST /api/v2/branches, count=N)
5. Let each branch run an independent patch or test strategy (POST .../exec)
6. Extract the winning diff / artifacts and delete losing branches
7. Sleep the winning computer between user turns ($0 active compute)
```

### Example: parallel best-of-N attempt runner (Python)

```python theme={"theme":{"light":"min-light","dark":"min-dark"}}
import concurrent.futures
import os
import uuid
import httpx

client = httpx.Client(
    base_url=os.environ.get("VERS_ORCHESTRATOR_URL", "https://api.vers.sh"),
    headers={"Authorization": f"Bearer {os.environ['VERS_API_KEY']}"},
    timeout=120.0,
)


def run_candidate(computer_id: str, patch_cmd: str) -> dict:
    res = client.post(
        f"/api/v2/computers/{computer_id}/exec",
        json={"command": ["bash", "-lc", patch_cmd], "working_dir": "/workspace"},
    ).raise_for_status().json()
    return {"computer_id": computer_id, "exit_code": res["exit_code"], "stdout": res["stdout"]}


def evaluate_candidates(base_checkpoint_id: str, candidate_cmds: list[str]) -> list[dict]:
    # 1. Fan out one isolated KVM branch per candidate strategy ($0 per branch)
    branches = client.post(
        "/api/v2/branches",
        json={
            "source": {"type": "checkpoint", "checkpoint_id": base_checkpoint_id},
            "count": len(candidate_cmds),
        },
    ).raise_for_status().json()["computers"]

    # 2. Execute each candidate concurrently in its own hardware-isolated VM
    with concurrent.futures.ThreadPoolExecutor(max_workers=len(branches)) as pool:
        futures = [
            pool.submit(run_candidate, branch["computer_id"], cmd)
            for branch, cmd in zip(branches, candidate_cmds)
        ]
        results = [f.result() for f in futures]

    # 3. Sleep the first passing branch for inspection; delete the rest
    winner_id = next((r["computer_id"] for r in results if r["exit_code"] == 0), None)
    for r in results:
        cid = r["computer_id"]
        if cid == winner_id:
            client.post(f"/api/v2/computers/{cid}/sleep").raise_for_status()
        else:
            client.delete(
                f"/api/v2/computers/{cid}",
                headers={"Idempotency-Key": str(uuid.uuid4())},
            ).raise_for_status()
    return results
```

## Guardrails for reliable agent harnesses

* **Prevent shell injection with direct-argv `exec`:** Pass `command` as an
  explicit string array (`["pytest", "-q", target_file]`) rather than
  interpolating untrusted model output into a shell string.
* **Control background processes explicitly:** `POST /exec` terminates leftover
  child processes when a command finishes unless you set `keep_background: true`
  (or pass `--keep-background` in `vers exec`). Use that when an agent starts a
  dev server or database that needs to stay alive for the next tool call.
* **Make retries safe with `Idempotency-Key`:** Agent harnesses retry on LLM
  rate limits and network blips. Store one UUID per logical create, checkpoint,
  or delete step and send it in `Idempotency-Key` so retries never orphan extra VMs.
* **Use `--json` when wrapping the CLI:** If your agent calls the `vers` binary
  directly, pass `--json` for structured machine-readable responses and check
  documented exit codes (`0`, `2`, `5`, `6`) in the [CLI reference](https://docs.vers.sh/cli-reference/overview.md#exit-codes).
* **Sleep idle computers between turns:** Interactive coding agents spend most
  of their wall-clock time waiting on LLM responses or human review. Call
  `POST /api/v2/computers/{id}/sleep` (or leave `keep_alive: false` for
  auto-sleep) to drop compute billing to `$0` while keeping RAM and disk intact.

## Next steps

> [card] [Python & TypeScript cookbook](https://docs.vers.sh/guides/python-and-typescript.md)
>
> Copy the full `/api/v2` client helpers in Python (`httpx`) or TypeScript (`fetch`).

> [card] [Multi-VM project networks](https://docs.vers.sh/guides/project-networks.md)
>
> Run and branch full `app + postgres` stacks for integration-testing agents.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.