Coding agents and computer-use agents

Repository agents, sandboxes, test-driven loops, browser and desktop control, and how they are evaluated.

Expert about 5 h

The picture

  1. 01

    Task

    issue or goal

  2. 02

    Explore

    read, search code

  3. 03

    Edit

    small diffs

  4. 04

    Run tests

    ground truth

  5. 05

    Iterate

    until green

  6. 06

    Review

    human merges

Why coding agents work best

Software gives an agent what most domains lack: fast, objective feedback. Tests pass or fail, the compiler complains, the linter objects. That is exactly the external signal reflection needs (see the planning topic). It is also why coding is where agents are most dependable today.

The loop

  1. Explore: search and read files rather than loading the whole repository.
  2. Plan the change briefly.
  3. Edit with small, reviewable diffs.
  4. Run the tests and read failures.
  5. Iterate, with a budget.
  6. Hand over a diff for human review. Do not let the agent merge itself.

The interface matters as much as the model. SWE-agent's central finding is that a purpose-built agent-computer interface (concise file viewers, a linter on every edit, search that returns compact results) raises success substantially compared with a raw shell.

A sandbox is not optional

An agent that runs code is an agent that runs untrusted code. Use:

docker run --rm -it \
  --network none --read-only --tmpfs /tmp \
  --memory 2g --cpus 1 --pids-limit 256 \
  --cap-drop ALL --security-opt no-new-privileges \
  -v "$PWD/workspace:/work:rw" -w /work \
  python:3.12-slim python task.py
  • No network by default; allow-list specific hosts only when needed.
  • Resource limits on memory, CPU, processes and wall-clock time.
  • A throwaway workspace (a copy or a git worktree), so mistakes are discarded.
  • No secrets in the environment. Provide scoped, short-lived credentials per task.

A minimal test-driven loop

import subprocess

def run_tests() -> tuple[bool, str]:
    p = subprocess.run(["pytest", "-x", "-q"], capture_output=True, text=True, timeout=300, cwd="workspace")
    return p.returncode == 0, (p.stdout + p.stderr)[-4000:]

def fix_until_green(agent, task, max_rounds=5):
    ok, log = run_tests()
    for _ in range(max_rounds):
        if ok:
            return True
        agent.run(f"{task}\n\nThe tests are failing. Fix the code (not the tests). Output of pytest:\n{log}")
        ok, log = run_tests()
    return ok

Note the instruction not to edit the tests, and consider enforcing it by mounting tests read-only: agents will otherwise sometimes make tests pass by weakening them.

Computer-use agents

Computer-use agents look at screenshots and issue mouse and keyboard actions. They can operate software with no API, but are slower, costlier and less reliable than API tools, and vulnerable to on-screen prompt injection (a web page telling the agent what to do). Run them in a disposable virtual machine or container, with no access to your logged-in sessions, and require human approval for anything consequential.

Reading benchmarks critically

SWE-bench (real GitHub issues with tests) and GAIA (general assistant tasks) are useful but imperfect. Check which variant was used, whether the score is pass@1 or best-of-n, the scaffold and compute budget, contamination risk, and whether the harness restricts the agent from seeing the tests. A leaderboard number tells you little about your codebase: build a small benchmark from your own past issues.

Common mistakes

  • Giving the agent your real credentials and network "to make it work".
  • Letting it modify the tests that judge it.
  • Trusting a benchmark figure without reading the evaluation setup.

Exercises

  1. Build a sandboxed fix-until-green loop for five small bug-fix tasks and report success rate and cost.
  2. Create a 10-issue mini-benchmark from your own repository's history.

You are done when you can…

  • Explain why tests make coding the best-suited agent domain
  • Design a sandbox for an agent that executes code or controls a browser
  • Read an agent benchmark such as SWE-bench critically