All posts

What Is an Agent Harness?

On this page

When tools like Claude Code, Cursor, Aider, or Devin read your files, edit code across multiple directories, run terminal tests, fix errors on their own, and stop only when the task is done, it is tempting to believe the underlying Large Language Model (LLM) is doing everything.

In reality, the AI model is not running your computer.

Raw language models do not have built-in terminals, cannot execute commands directly, and do not maintain active processes. The software system wrapping around the model is called an Agent Harness.

The Core Problem

Modern foundation models are extraordinary reasoning engines. Given a prompt, they can understand intent, explain complex code, and plan multi-step solutions.

However, a raw LLM suffers from four fundamental constraints:

  1. Passive & Text-Bound: An LLM only accepts tokens and produces tokens. It cannot open a file on your disk, inspect an active database, or trigger a command.
  2. Stateless & Amnesiac: Once an API call ends, the model resets. It does not natively retain long-term state across sessions without external context injection.
  3. Information Blindness: An LLM cannot digest a 50,000-file repository in one go. Dumping entire codebases into the prompt wastes tokens, causes context pollution, and degrades reasoning.
  4. No Real-World Feedback: The model can output code, but it cannot know if the code actually compiles, runs, or breaks until something tests it and returns the output.

If the model is the brain, the harness is the body, operating system, and nervous system combined.


How an Agent Harness Solves These Problems

There is no fixed blueprint for a harness. Different tools make different trade-offs: some run entirely in your local shell, others provision full containerized sandboxes, some ship sophisticated memory systems, others none at all. What follows are responsibilities that most well-built harnesses cover:

Providing Tools

Instead of asking the model to magically edit files, the harness exposes structured capabilities—increasingly standardized via protocols like MCP (Model Context Protocol) such as read_file, write_file, grep_search, or execute_command.

  • The LLM emits structured intent (e.g., “Run npm test).
  • The harness intercepts the command, runs it, and feeds the output back to the model.

One nuance: modern models are post-trained for tool calling, so deciding when to call a tool is partly model capability. The harness's job is to define, execute, and govern those calls—it decides what the model is allowed to do, not what it wants to do.

Context & Memory Management

Feeding too much information degrades an LLM's attention. The harness handles progressive context discovery:

  • Loads project rules (AGENTS.md or CLAUDE.md).
  • Fetches only relevant file trees, function signatures, or search snippets when requested.
  • Compacts or summarizes historical turns—or offloads large tool outputs to the filesystem—so the context window never overflows during long-running tasks.

Safe Execution Sandboxes

The harness provisions isolated environments—such as containerized sandboxes, virtual filesystems, or shell subprocesses—where code can run without corrupting the host machine or leaking sensitive environment variables. This one varies a lot in practice: some tools run agent code in fully isolated containers, while others execute directly in your local shell and lean on git for rollback.

The Feedback Loop (Reason -> Act -> Observe -> Adjust)

Autonomy requires closed-loop execution:

  1. Reason: The model analyzes current context and plans the next atomic step.
  2. Act: The model requests a tool call (e.g., modify line 42 in auth.ts).
  3. Observe: The harness executes the change, triggers test suites, and captures the error output (e.g., AssertionError: Token is null).
  4. Adjust: The harness feeds the trace back to the model to reason and self-correct.

Guardrails & Governance

Autonomous agents can be unpredictable. The harness enforces deterministic execution states and permission tiers:

  • Safe Actions (Auto-approved): Reading a file, running a read-only query, running unit tests.
  • Sensitive Actions (Require Human Approval): Deleting tables, overwriting critical files, publishing commits, or running destructive shell scripts.

Observability & Tracing

When an agent works autonomously for 15 minutes, developers need transparency. The harness records every tool invocation, latency metric, token expenditure, and intermediate failure.


Comparing the Model vs. The Harness

ResponsibilityThe LLMThe Agent Harness
Primary JobReasoning, synthesis, code generationState management, file I/O, tool execution
Context HandlingInterprets tokens provided to itDecides what tokens to include or prune
VerificationAssumes output looks syntactically validRuns linters/compilers to prove correctness
SafetyTries to follow ethical prompt guidelinesHard-blocks unauthorized filesystem/network calls
PersistenceNone (stateless API)Retains scratchpads, todo lists, and task logs

Why the Harness Is Where True Leverage Lives

Two engineering teams can build products using the exact same underlying LLM, yet achieve radically different outcomes:

  • Product A passes your prompt directly to the model and streams back a block of code.
  • Product B uses a purpose-built harness that indexes your codebase, executes unit tests, applies linter back-pressure to catch syntax issues, and checks every change against your existing test suite before presenting a finished pull request.

The difference in performance is not model intelligence, it is harness engineering. The same model can rank near the bottom or near the top of agentic benchmarks depending purely on the harness wrapped around it.


Harnesses Are Temporary Scaffolding

One caveat worth internalizing: a harness largely compensates for current model limitations, and those limitations shift with every model release. Capabilities that required hand-built pipelines a year ago may now be handled natively by the model.

There's also a feedback loop at play: model vendors now post-train models with their harnesses in the loop, which is why a model often performs best inside the harness it was trained with and why harness and model design are increasingly co-evolving.

The practical takeaway: build harnesses to be modular and easy to simplify, so each component can be removed the moment the model absorbs its job.


Wrapping Up

Thank you for reading! If you found this breakdown useful, please share it with your team and colleagues.

If you haven't already, feel free to connect with me on LinkedIn.