Free guide

What Is Harness Engineering? A Guide for AI Agents

Harness engineering explained for AI agents: components, how it differs from prompt and context engineering, gates and declared bounds. With examples.

PDF · Free download

Keep this guide as a PDF

What Is Harness Engineering? A Guide for AI Agents, as one file you can read offline and share with your team.

Sign in with Google or GitHub to download.

Sign in to download

Harness engineering is the work of building everything around an AI model, meaning its tools, context, memory, permissions, checks and limits, so that an agent can finish multi-step tasks reliably. This guide is about AI agents, not the wire harnesses in cars and aircraft or the Harness CI/CD product.

Most guides stop at the parts list. The part that decides whether an agent can be trusted is smaller and more specific: a check that the agent cannot write to, and limits on attempts, time and tokens that are declared before the run starts. That is what the Bounded Loops paper formalises, and the second half of this guide shows it running.

Disclosure. Qualixar builds several open-source tools mentioned here: Bounded Loops, Agent Amplifier, ModStage, SuperLocalMemory and the Jev Decision Layer. I am not a neutral reviewer. Claims about other people's work are labelled as theirs and linked to their source, as checked on 24 November 2026.

What is harness engineering?

The shortest working definition is "agent = model + harness". DigitalOcean's explainer attributes the formula to LangChain's Vivek Trivedy and describes harness engineering as designing the tools, context, constraints, feedback loops and runtime around a model so it can carry out multi-step work reliably (DigitalOcean, Nov 2026). A keynote at QCon San Francisco put it as the harness being everything in an agent that isn't the model, according to InfoQ's report.

An academic source-code study of eleven coding agents, including Claude Code, Codex CLI, Gemini CLI and Hermes, defines the harness as the runtime that connects a model to its environment through a loop, tools, context management, safety controls, orchestration and extension points. The same paper says harness engineering was named as a discipline in early 2026 (arXiv:2609.00006).

Two practical consequences follow. Claude Code is itself a harness, and so are the other ten systems in that study. And when someone says they are "building a harness", they usually mean one of two jobs: configuring an existing harness with rules, hooks, memory and skills, or writing the runtime themselves.

How is harness engineering different from prompt, context and loop engineering?

The sources disagree about where the boundary sits. Thoughtworks' glossary entry defines it as improving the environment the models operate in, quotes its Americas CTO Thomas Squeo calling it the discipline of "designing the controls around the AI agents", and never mentions prompt or context engineering (Thoughtworks, Aug 2026). DigitalOcean, by contrast, lists context, memory and durable state among the harness components.

So the edges are convention. The table below is the sorting this guide uses. It is my working definition, and no source cited here states it in this form.

Term What it shapes Typical artifact
Prompt engineering The words in one request A prompt
Context engineering What is in the model's window at each step Instruction files, retrieved notes, summaries
Loop engineering How the agent repeats work and when it may stop A loop with an exit test (our loop guide)
Harness engineering Everything around the model, including the three above Tools, hooks, sandbox, memory, checks, limits

My rule of thumb for sorting a problem: if the fix is wording, it is a prompt problem. If the fix is what the model can see, it is context. If the fix is when to retry or stop, it is a loop. If a rule must hold no matter what the model decides, it belongs in the harness. The last case is not hypothetical. Claude Code's documentation says CLAUDE.md files and auto memory are treated as context and "aren't enforced configuration", and tells you to use a PreToolUse hook to block an action regardless of what Claude decides (Claude Code docs).

What are the parts of a harness?

Explainers slice it differently. The five parts below are this guide's grouping of what DigitalOcean, DataCamp and the source-code study describe.

Diagram: an agent is a model plus a harness. The harness has five parts: Tools, Context and memory, Hooks, Sandbox and permissions, Observability.Agent = model + harnessModelHarnessToolsContext andmemoryHooksSandbox andpermissionsObservability
The five parts of a harness, as grouped in this guide: Tools, Context and memory, Hooks, Sandbox and permissions, Observability.

Tools. The model acts only through tools the harness exposes. DataCamp's tutorial builds two, a bash runner that starts in a workspace/ directory and a file writer that refuses paths outside it (DataCamp, Sep 2026). The bash runner only sets its working directory, so the tutorial's sandbox is a starting point and not a boundary.

Context and memory. Instruction files and memory decide what the model knows at the start of a step. In Claude Code, CLAUDE.md and auto memory both load into each session as context (Claude Code docs); DataCamp injects an AGENTS.md file into the system prompt on every turn. Memory has its own failure modes, covered in our Claude Code memory guide.

Hooks. Hooks are deterministic code that runs at fixed points. The Claude Code documentation says hooks execute as shell commands at fixed lifecycle events, so they apply whatever the model decides (Claude Code docs). DataCamp's example runs pytest after every Python file the agent writes and feeds the failures back to it. Our Agent Amplifier is a set of five Claude Code hooks for effort routing, goal anchoring, convergence detection and token budgeting. Its README says they are deterministic Python with no extra LLM calls on the Claude Code path, apart from an optional local embedding model.

Sandbox and permissions. DigitalOcean lists sandboxes, permissions and tool access as their own component. The point of the layer is that the agent cannot widen its own reach.

Observability. ModStage (source), a Claude Code plugin from Qualixar, runs other coding agents as subagents inside Claude Code and shows each step live, lets you steer mid-run and puts risky actions behind an approval, per its README.

The source-code study adds two observations worth knowing. Skills were adopted by nine of the eleven systems and MCP by eight of eleven. And across about four million lines of code, none of the runtimes used a general-purpose agent framework, and none used vector embeddings for code retrieval (arXiv:2609.00006). In those eleven systems, hand-built loops and deterministic retrieval are the norm, so a harness is not a framework you install.

What do harness guides leave out: gates, bounds and receipts?

The field already knows verification matters. DigitalOcean's guide says to check the artifact, such as passing tests, and not the transcript. It names step limits and retry checks as cost controls and gives no token or dollar budget. LangChain found that the most common failure in its coding agent was writing a solution, rereading it, judging it fine and stopping, and it added a checklist step that reminds the agent to run a verification pass before it exits (LangChain, Feb 2026).

DataCamp's tutorial caps its loop at 15 steps, which bounds steps and not time or tokens. Its pytest hook also treats exit code 5 as a pass, and a comment in the code says exit code 5 means "no tests collected", "which is fine for our purposes" (as read from the page on 24 November 2026; DataCamp refuses automated raw fetches, so the code was read through a page reader and not from the HTML). That is a reasonable shortcut in a teaching example. It is also a check that passes when there is nothing to check, which is the first defect class described below.

Neither explainer describes a check the agent cannot write to, a wall-clock limit enforced while an attempt is still running, or a record you can re-verify afterwards. Those are the three ideas in the Bounded Loops paper and its repository (the product page is Bounded Loops):

  • A gate is the check that decides pass or fail. It is a command, a test suite or a schema, never the agent. The agent's own "I'm done" is written to the record and ignored.
  • A bound is a limit you declare before the run: attempts, tokens, wall-clock time, attempts without progress. The engine enforces it and stops.
  • A ledger is the append-only, hash-chained file of what happened. A verify command re-checks it, so "it passed" is something you can confirm rather than trust.
Diagram: a bounded loop. A worker makes an attempt, and a gate that the agent cannot write to decides pass or fail. A pass ends the run as done, and a fail sends the worker back for another attempt inside the declared bounds of attempts, tokens and wall-clock time. A ledger records every step as an append-only, hash-chained file.Bounds, declared before the runattempts · tokens · wall-clock timeWorkerthe agentGatea check the agentcannot write toDoneonly on a passattemptpassfail: try again, inside the boundsLedgerappend-only, hash-chained, re-checked with verify
A gated loop. The gate, not the agent, decides pass or fail, and the bounds are declared before the run.

Those three definitions are the README's. The paper turns them into guarantees. A bounded loop is a worker, an independent gate the worker cannot write to, and a declared budget. Graphs of such loops get three properties. They finish, because termination holds under repair and the worst-case attempt total can be read from the manifest in closed form. They do not drift, because no node reaches DONE without a gate verdict in the ledger. And they do not overrun the declared ceiling, because it is enforced inside an attempt and not only between attempts.

Be precise about that third property. What the paper proves is a wall-clock bound, which it calls bounded elapsed spend: total run time is at most the declared ceiling plus one gate timeout. The token budget is counted across attempts (the README's bounds table says "accumulated runner usage"), and neither document claims a cap in dollars. The README is also plain about the gate: the engine checks that worker and gate are different objects, and it does not prove that the gate's logic is independent. This is the kind of work we group under AI Reliability Engineering: making agent behaviour checkable instead of trusted.

The paper also names two ways a sound-looking gate can pass anything. A vacuous gate is satisfied by the absence of the thing it checks. The paper's own example is a ledger-reconciliation gate that checked debits equal credits and every transaction has a category, both of which are true of an empty ledger. A self-attesting gate lets the subject supply the value the check is applied to. On the paper's 69-loop catalogue, the measuring instrument found 47 vacuous gates in shipped, reviewed code. The 47 is a count of gate defects, each pinned as a regression test in the repository, so do not read it as 47 of the 69 loops. That catalogue is ours, which is the point: reviewed code still shipped checks that pass on nothing.

The paper is also careful about what it does not show. Against the repaired gates it reports no false accepts over 209 destroying mutants, an upper bound of 1.8% at 95% Wilson confidence. It then says that figure is saturation, not quality: freezing the gates and applying a fresh family of mutation operators recovered a 23.3% false-accept rate where the exhausted corpus had reported none. A rate belongs to a specific gate. The paper says the apparatus, not that number, is its contribution.

A small piece of arithmetic shows why gates matter at all. If a task has twenty steps and each step succeeds 95% of the time, and steps fail independently (a simplifying assumption), the whole task finishes cleanly about 36% of the time, because 0.95 to the twentieth power is 0.358. InfoQ's report of the QCon keynote makes the same point and adds that catching 80% of step errors lifts the total to 82%. Catching an error requires something outside the step that can notice it.

How can I run a gated loop today?

The repository ships a keyless example: the worker is a stub, and the pytest gate is real. Run on 24 November 2026 with bounded-loops 0.7.6 from PyPI (the README describes 0.7.7):

python -m pip install bounded-loops
bl loops install bug-fix-red-green --dest ./loops
./loops/bug-fix-red-green/wreck.sh      # the ungated twin
bl run loops/bug-fix-red-green --yes --run-id first-proof

The paper's figures, including the 47 vacuous gates and the 23.3% false-accept rate, come from v0.6.6, and the version installed here is newer, so this run demonstrates the mechanism and does not replicate the paper.

The ungated twin trusts the agent's word. Its output, trimmed:

=== bug-fix-red-green — WRECKED (no gate) ===
WARNING: this loop trusts the agent's own claim — it never checks pytest.

--- Lap 1 (no gate) ---
<promise>GREEN</promise>

LOOP BELIEVES: agent claimed GREEN on lap 1 — exiting (no gate confirmed this).
...
LIE CONFIRMED: pytest still FAILS, but the ungated loop already exited claiming success.

The pytest output printed after it in the same run ends with 1 failed, 5 passed. The loop left on a false promise. The gated run, with an absolute path shortened:

[bounded-loops] About to run loop 'bug-fix-red-green':
  runner : stub
  gate   : pytest -q
✓ [DONE] gate-passed (laps: 1)  ledger: .../first-proof/ledger.jsonl
Gate verified: the independent acceptance gate passed after 1 lap.

The receipt can be checked afterwards with bl verify <run dir> --expect-head <digest>. In this run it reported the ledger intact and complete, with one ledger row for one recorded row. It also stated its own limit: the head check is strong only if you kept the digest outside the run directory, because a digest copied out of that directory proves nothing about someone who rewrote the directory wholesale.

What this does not show: a stub worker applies a known fix, so the example proves gate and receipt mechanics and says nothing about any model's skill. A gate is only as good as what it checks, which is the vacuity problem again. For the longer treatment, see our loop engineering guide, the film Loop Engineering Vol. 1 and the film Why AI agents say done when the work isn't.

What does a declared bound look like?

This is the bounds.yaml shipped with the bug-fix example, copied from the repository:

max_iterations: 15
no_progress_window: 3
max_tokens: null
max_wallclock_s: 1440
sandbox: true
quarantine_inputs: true
schema: null
trace: true
require_approval: false

max_iterations is the attempt limit. no_progress_window stops a loop that has gone three attempts without improving, which catches the case where an agent is busy and getting nowhere. max_wallclock_s is a time limit in seconds, here twenty-four minutes. max_tokens is null in this example. The paper describes that field as a cumulative token budget across attempts, or unset, so this loop has no token limit, and a loop that spends real model tokens should set one. The remaining fields control isolation and review: whether the run is sandboxed, whether inputs are quarantined, whether a human must approve. The point is that every one of these is fixed before the agent starts and enforced by the engine, so the agent cannot argue its way past a limit.

The paper's stronger claim is about where the wall-clock limit is enforced: inside an attempt, so one long attempt cannot run far past it. The example above uses a stub worker that finishes in well under a second, so it does not exercise that property, and the YAML alone demonstrates nothing about it.

Where can I read real harness designs?

Two recent papers are worth your time, both independent of us. The eleven-system source-code study (arXiv:2609.00006) catalogues 29 recurring design patterns and 13 cross-cutting observations, closes with 18 design recommendations and ships a 90-line minimum-viable-harness scaffold. It also reports behavioural policy moving from prompt text into configuration over the quarter it tracked, which fits the argument above about moving must-hold rules out of instructions.

The second, (arXiv:2611.19960), is a single-author catalogue of 30 decision cards for harness builders, where each card lists options and costs, an invariant, the corner cases that violate it and a test. Its author is open about the limits: the cards come largely from one desktop harness plus manual testing of ten others, and of 83 invariant clauses 56 are tagged Tested, 12 Believed and 15 Open. Applied as a checklist to the author's own harness, eleven of thirty items held, fourteen did not and five were not tested. It makes no ranking claims. Both papers are descriptive, which makes them good maps and poor benchmarks. Qualixar's own preprints are listed on the research papers page.

Does harness engineering matter more than the model?

There is real evidence that the harness moves results on a fixed model. LangChain reports raising its coding agent from 52.8% to 66.5% on Terminal Bench 2.0, an 89-task benchmark, with the model held at GPT-5.2-Codex and the prompt, tools, middleware and reasoning budget changed (LangChain, Feb 2026). That is the vendor's own agent, one benchmark and one model, so read it as an existence proof and not as a general rate.

There is also evidence that more harness is not always better. InfoQ's account of the QCon keynote cites a result where DeepSeek scored between 65.5% and 74.2% on DeepSWE across eight harnesses, with the minimal ones highest. That figure is second-hand: InfoQ attributes it to DeepSeek's model card, which was not read for this guide. The community argument runs in both directions too, including a Reddit thread titled "Harness is overrated" and another asking what an AI harness actually is and why companies hire for it.

My reading of this evidence: it supports "the harness changes results on a fixed model", and it does not support "the harness beats the model". None of the sources consulted for this guide measured both on equal footing. The longer version of that argument is in it was never the model, which is an opinion piece. To find out for your own setup, fix the model and the task set, change one harness component at a time, and count false "done" claims as well as the pass rate. A harness that raises the pass rate while hiding failures has made things worse.

What mistakes do harnesses make?

Six show up in the sources. Three of them, the first, fourth and fifth, are failures reported in our own papers.

A check that passes on nothing. This is the vacuity class above, 47 defects in one reviewed catalogue.

An agent that grades its own work. This is self-attestation, and it is what the ungated example above does.

A must-hold rule written as an instruction. Claude Code's documentation is explicit that CLAUDE.md content is context, not enforced configuration, and that behaviour which must happen at a fixed point should be a hook.

A mechanism that exists but does not work. The SuperLocalMemory 4.0 paper leads with a negative result: ten mechanisms were implemented and reachable on a live call path, yet ineffective at their final connection. Its lesson is that "implemented", "reachable" and "effective" are three different questions, and the third needs a check independent of the mechanism under test (arXiv:2608.08253).

A limit that is declared and not enforced. The Bounded Loops paper reports this about its own engine: all 69 loop manifests in the catalogue declared a wall-clock ceiling, and the engine compared it with elapsed time only at the top of each attempt. A loop that declared a two-minute ceiling ran a single attempt for more than five minutes and was stopped by an unrelated runner default.

A step cap mistaken for a time or token cap. Stopping after 15 steps says nothing about how long those steps ran or how many tokens they used.

How do I start?

Pick one repeatable task and write its exit test first, as a command that fails until the work is right. Run the agent against a gate it cannot edit, which means keeping the test command outside the workspace the agent can write to. Declare bounds before the run: attempts, tokens, wall-clock time and a no-progress window. Move every rule that must hold out of instruction files and into hooks or permissions. Where a step needs a bounded choice, such as which tool or model to use, the Jev Decision Layer from Qualixar gives an agent typed, advisory decisions for harnesses. Then keep the receipts, count how often the agent's own "done" disagrees with the gate, and audit any gate that has never rejected anything, because a gate that never fails may be checking nothing.

FAQ

What is an AI harness, and why would a company hire for one instead of just using Claude Code? A harness is everything around the model, and Claude Code is one. Whether a company should build its own depends on how well a general harness fits its repositories, CI and permission rules. No hiring data was verified for this guide, so it makes no claim about hiring trends.

Is harness engineering just prompt engineering with a new name? No, though they overlap. A prompt is words in a request. A harness includes code that runs regardless of the words, such as hooks, permission rules, gates and declared limits.

Should I use the harness the model was trained with? No source consulted for this guide measures this, so there is no answer here to guess at. Run your own task set against both and compare the pass rate and the false-done count.

What belongs in a harness: hooks, memory, tools, sandbox? All four, plus observability and declared limits. The five-part list earlier in this guide is one way to group them.

How do I know my harness helps? Hold the model and tasks fixed, vary one component, and measure both the pass rate and how often the agent claims done when it is not. LangChain's 52.8% to 66.5% result is the template, with the caveats that it is one vendor's benchmark and that it changed several things at once.

How is harness engineering different from an agent framework such as LangGraph? A framework is a library you build on. A harness is the finished runtime around a model. The source-code study found that none of the eleven coding agents it read was built on a general-purpose agent framework, so the two are different layers of the stack.

What stops an agent from saying "done" when it is not? A gate that is independent of the agent: a command or test suite the agent cannot write to, whose verdict is the only thing that moves a task to done. The agent's own claim is recorded and ignored.

Want more guides like this?

Subscribe to get weekly AI agent reliability insights and new guide notifications.