When AI agents fail repeatedly, the cause can be the design of the environment in which the model works, alongside limits in the model's intelligence. Harness engineering equips an agent with tools, memory, verification, permissions, and recovery so its behavior can be trusted. Beyond looking for a stronger model, it means turning failures into improvements that help on later runs.
1. Why Agents Fail Even After You Improve the Prompt
When an agent doesn't work properly, people often start by editing the prompt, switching models, or moving to a model with a longer context window. The agent can still forget earlier decisions, choose the wrong tool, skip verification, or repeat a mistake.
The piece argues that alongside the intelligence of the model, you should examine the environment around it. That environment is the harness, and designing it is harness engineering.
Anthropic CEO Dario Amodei said this when explaining how Claude Code came about.
"Of course, to use the model you need an interface, you need a harness."
2. The Model Reasons and the Harness Provides the Environment
The model can reason about what to do next and propose an action. A stable working environment takes more. The harness determines what the model can see and which tools it can use, what persists after the session, what evidence counts for verification, and when a run should stop.
The prompt and the model are parts of the larger system. Product quality depends on context selection, tool provision, state storage, permissions, verification, logging, and recovery working together.
"Prompt engineering improves the instructions.
Harness engineering improves the conditions in which those instructions run."
Put the same model in a chat box and it answers questions. Give it a repository, terminal, tests, browser, project memory, isolated workspace, and review process, and it can build and deploy software. The difference is the harness. The model weights stayed the same.
When OpenAI built a codebase around Codex, it attributed slow early progress to an underspecified environment more than to a lack of raw model capability. Instead of urging the agent to try harder, the team identified the missing capabilities and made them understandable and usable by the agent.
"The environment was underspecified."
— OpenAI, Harness engineering: Leveraging Codex in an agent-first world
3. Seven Jobs for a Production Harness

Turn the Request into a Clear Task Contract
Before the agent acts, specify the goal, inputs, deliverables, constraints, and completion criteria. For a feature, the inputs might be an issue, repository, and design. The deliverable might be a reviewable pull request. State constraints such as keeping the database schema and existing public API, and require tests, a visual check, and review for completion.
Without this contract, an agent can finish a different task and still declare success.
Provide a Map of the Project
The agent needs project knowledge. It doesn't need every document in context at once. A short guide such as AGENTS.md can point to architecture, test instructions, product rules, security rules, and guides for specific tasks.
Keep detailed knowledge close to the relevant code, tool, or workflow, and load it as needed. As the piece puts it, a map preserves context, while a huge manual consumes it.
Provide the Right Tools in the Right Environment
Tools connect the model to the real world. They are more than a list of buttons. Each tool needs a clear purpose, predictable output, explicit failure states, and a permission boundary.
For example, allow file reads by default, run tests in isolation, and limit writes to the workspace. Limit network access to the scope of the work and require approval before deployment or data deletion. A good tool reduces ambiguity before the model has to guess. A bad one leaves the model guessing what happened.
Save Memory as Persistent State Outside the Conversation
A chat is a poor system of record. Store decisions, outputs, failures, and remaining risks in structured form outside the context window.
For example, record that the current stage is UI verification, the existing schema will stay, a 390 px mobile screen showed overflow, and approval is still pending. The next session then inherits the actual state of the work instead of depending on a potentially inaccurate chat summary. That lets work survive a context reset, a crash, or a handoff.
Set Up Observability Before Increasing Autonomy
Agents cannot fix problems they cannot observe. Check quality with tools such as tests, static checks, screenshots, logs, metrics, and data validators.
- Code. Tests, type checks, and style checks.
- UI. Rendering, screenshots, and visual inspection.
- Research. Check sources and conflicting information.
- Data. Check schemas, value ranges, and freshness.
The model creates an output. The environment produces evidence about that output. The harness decides whether there is enough evidence to proceed.
Enforce Permissions Outside the Model
The model can propose an action. Approval belongs outside the model. The sequence is model proposal → policy check → tool execution.
The distinction matters most for costly or irreversible actions and actions that affect other people. The same probabilistic system should not be responsible for planning an action, approving its risk, and executing it.
Log Each Run and Make Recovery Possible
For every run, keep a readable record of the request, selected context, tool calls, state changes, verification results, retries, cost, final output, and rollback point.
Without records it's difficult to see why something failed. With them, failures can inform the next harness improvement.
4. Turn Important Instructions into Checks That Are Hard to Bypass
A team can document important rules, but an agent can read them and still overlook one later. Keep important rules in two forms: instructions people and agents can understand and mechanical checks that are hard to bypass.
You might write that UI code must not access the database directly, then configure a check to fail when UI code imports the data access layer. The instruction explains the reason, and the check enforces the boundary.
The next agent doesn't have to remember an earlier incident. The harness remembers the failure for it.
5. Let the Harness Control Repetition
Long-running tasks require iteration. Simply saying "keep trying until it works" gives you little control. A useful loop needs verification evidence, a retry limit, a budget, and a route to human review.
For example, generate an output and verify it. If it fails, record what is missing and what to change, then allow up to three retries. If it still doesn't pass, ask a person to review it. The model decides how to address the specific problem, and the harness decides whether another attempt is allowed.
In its research on long-running agents, Anthropic also stressed using structured artifacts to maintain continuity across sessions and a separate evaluator to give the working agent concrete feedback. This avoids having the agent that generated an output approve its own work.
"Find the simplest solution possible and add complexity only when you need it."
— Anthropic, Harness design for long-running application development
6. Fix the Class of Failure

Fix the current output and you improve one run. Fix the harness and that improvement applies to every subsequent run.
- Missing context. Add a project map or a rule for finding information.
- Wrong tool. Improve tool descriptions or selection.
- Poor output. Add a validator or make the task contract clearer.
- Repeated behavior. Add a retry limit and a route to human review.
- Unsafe action. Add an authorization step.
- Forgotten decision. Save it in persistent state.
- Unexplained failure. Improve tracing and evidence collection.
"A good harness turns agent mistakes into infrastructure."
7. Separate Reasoning, Action, and the Record
Think of a reliable agent as three components. The brain is the model that reasons. The hands are the sandbox and tools that carry out actions. The record is the append-only history of what happened.
With that separation, the history survives the shutdown of a sandbox. Tools and policies can be examined separately when you change models. When work resumes, a new session can reconstruct state from the artifacts and execution history.
The piece cites Anthropic's Managed Agents as making this separation explicit through sessions, harnesses, and sandboxes. The broader point is to keep the reasoning engine from doubling as the filesystem, permission system, memory store, and audit log.
8. Leave a Change Receipt for Each Run
A final output alone does not show how it was made. Keep a concise change receipt for each run.
A receipt can list sources of context, the policy version, model route, tools used, tests passed and failed, human edits, retries, cost, approved artifacts, and the rollback point.
The record helps you compare behavior after changing models, trace regressions, and perform audits. It also makes it harder for a plausible final answer to hide a flawed process.
9. Start with the Smallest Harness That Suits the Work
Harness engineering does not require a huge platform before the first task. Start with the smallest system that lets you observe, verify, and recover, and expand it to fit the risk and complexity of the work.
- Level 0. A prompt and a model.
- Level 1. Project guidance and tools.
- Level 2. Structured state, tests, and bounded iteration.
- Level 3. Permissions, execution logs, recovery, and human approval.
A short, low-risk task may need only one prompt and one review. A six-hour coding task that edits files, accesses the network, and opens a pull request calls for a proper harness. The piece argues that the harness should stay smaller than the failure surface it is meant to control.
10. Questions to Ask Before Trusting an Agent with Real Work
The piece recommends checking these questions before relying on an agent.
- Is success defined before execution?
- Can the agent find the project knowledge it needs without loading every document?
- Are the conditions for using each tool and its failure states clear?
- Is execution isolated from production?
- Are important decisions stored outside chat?
- Does every risky step have evidence to support the decision?
- Do irreversible actions require approval?
- Does every loop have a retry limit and a budget?
- Can a run resume after interruption?
- Can you account for every tool call and state change?
- Do failures lead to better guides, tests, tools, or policies?
- Can the final output be rolled back?
If several answers are "no," a stronger model alone won't make the system trustworthy. It may increase the cost of failure.
11. The Advantage Moves from the Prompt to the System
The piece closes by distinguishing related ideas. Prompt engineering tells the model what to do. Context engineering determines what it sees. Harness engineering builds the operating environment where it acts. Loops handle local improvement, and graphs coordinate multiple tasks.
Models change. Tools, tests, state, policies, and execution records can keep improving. A good builder asks which model is most capable and, more importantly, what environment makes it possible to use that intelligence reliably.
The author invites readers to save the checklist for their next agent and follow the topic through the author's newsletter, Telegram, and X account.
