# What is an agent harness? The code that runs an AI agent

URL: https://sdclabs.com/glossary/agent-harness/

> An agent harness runs the model loop, tools, permissions, context and checks around an LLM. What it does, harness vs framework, and a runnable example.

# What is an agent harness?

[Mykhailo Poliarush](https://sdclabs.com/author/poliarush/) 2026-11-25

Definition

An agent harness is the code around an AI model that turns it into a working agent. It runs the loop of model calls, executes tool calls under permissions, chooses what enters the context, saves progress between sessions, and checks results before work counts as done. Claude Agent SDK and LangChain's Deep Agents are examples.

## What does an agent harness do?

The model only predicts the next message. Everything that turns that prediction into finished work is the harness. In AI engineering the term has nothing to do with Harness, the CI/CD software company.

A harness usually owns six jobs:

| Job | What the harness decides | What goes wrong without it |
|---|---|---|
| Run the loop | When to call the model again, when to stop, how many steps and dollars a run may spend | Runs that never end, or end early |
| Execute tools | Which tools exist, which calls are allowed, denied or sent to a person | The model gets every permission it asks for |
| Fill the context | Which instructions, files, tool results and history go into each call | The context window fills with noise |
| Keep state | Progress notes, git commits, handoff files between sessions | A fresh session cannot tell what was done |
| Verify | Tests, linters or a separate evaluator that the model cannot edit | The agent marks unfinished work as done |
| Record | Logs and traces of every call and result | Nobody can debug a bad run |

The third job has its own name. Context engineering is the practice; the harness is where that practice runs as code.

## How is an agent harness different from a framework or a runtime?

LangChain's documentation separates the three layers, and the split is useful outside its own products ([LangChain, runtimes, frameworks and harnesses](https://docs.langchain.com/oss/python/concepts/products) ):

| Layer | What it adds | Examples LangChain lists |
|---|---|---|
| Runtime | Durable execution, streaming, human-in-the-loop, persistence | LangGraph, Temporal, Inngest |
| Framework | Abstractions and integrations for models, tools and the loop | LangChain, Vercel's AI SDK, CrewAI, OpenAI Agents SDK, Google ADK, LlamaIndex |
| Harness | Predefined tools, prompts and subagents, ready to run | Deep Agents SDK, Claude Agent SDK, Manus |

The same page calls harnesses "opinionated, batteries-included" and lists what they usually ship with: a to-do list for planning, subagents for delegation, a file system, and token management through history summarization and eviction of large tool results. A framework gives you parts. A harness gives you a working agent with defaults you can change.

One more name collision: an evaluation harness runs test tasks and grades them. That belongs to [AI evals](https://sdclabs.com/glossary/ai-evals/) , not to the agent itself.

## How much does the harness change the result?

More than most teams expect, judging by published experiments. In a [March 24, 2026 post](https://www.anthropic.com/engineering/harness-design-long-running-apps) , an Anthropic engineer asked for the same retro game maker twice. A solo agent ran 20 minutes for $9. A harness with a planner, a generator and an evaluator ran 6 hours for $200. The harness cost over 20 times more, but only its version had a game that worked: in the solo build, entities appeared on screen and did not respond to input.

The same post gives the rule worth keeping: "every component in a harness encodes an assumption about what the model can't do on its own." When Opus 4.6 shipped, the author removed the sprint structure entirely and kept the planner and evaluator, which still added value. A browser audio workstation built with the slimmer harness took 3 hours 50 minutes and $124.70.

An earlier Anthropic post, from [November 26, 2025](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents) , shows the failure modes a harness has to absorb. Agents tried to build the whole app at once and ran out of context mid-feature. Later sessions saw progress and declared the job done. Features were marked complete without an [end-to-end test](https://sdclabs.com/glossary/end-to-end-testing/) . The fixes lived in the harness: a JSON list of more than 200 features that all start as failing, a progress file plus git history for the next session, an init.sh that starts the dev server, and browser automation for testing like a user.

OpenAI calls this work harness engineering. In a [February 11, 2026 post](https://openai.com/index/harness-engineering/) , its team reports that about 1,500 pull requests were opened and merged in five months with no hand-written code, by three engineers driving Codex (an average of 3.5 PRs per engineer per day). Two harness choices stand out. AGENTS.md stays at roughly 100 lines and works as a map to a structured docs/ folder, because one large instruction file crowded out the task. Custom linters write their error messages as fix instructions, so a failed check tells the agent what to change.

## Example: a small harness around a stub model

The model below is a stub that replays four proposals, so the file runs without an API key. The harness decides what happens to each proposal: it runs allowed tools, blocks a denied one, cuts long results, caps the steps and checks the result with code the model never touches.

// harness.mjs: the code around a model call. The model only proposes the next tool call; // the harness owns permissions, output limits, the step budget, verification and the log. import { appendFileSync, readFileSync, rmSync } from "node:fs"; const files = { "src/price.js": "export const total = (a, b) => a - b;" }; const tools = { read: ({ path }) => files[path] ?? `no such file: ${path}`, edit: ({ path, text }) => ((files[path] = text), `wrote ${path}`), shell: ({ cmd }) => `ran ${cmd}`, }; const policy = { read: "allow", edit: "allow", shell: "deny" }; // set by you, not the model const MAX_STEPS = 5; const MAX_RESULT_CHARS = 40; // long tool results are cut before they reach the model // Stub model: replays proposals so the harness runs without an API key. const proposals = [ { tool: "read", args: { path: "src/price.js" } }, { tool: "shell", args: { cmd: "git push --force" } }, { tool: "edit", args: { path: "src/price.js", text: "export const total = (a, b) => a + b;" } }, { done: true }, ]; const model = (history) => proposals[history.length]; // A check the model cannot edit: load the file it changed and test it. async function verify() { const mod = await import("data:text/javascript," + encodeURIComponent(files["src/price.js"])); return mod.total(2, 3) === 5; } rmSync("progress.log", { force: true }); const log = (line) => appendFileSync("progress.log", line + "\n"); const history = []; let status = "stopped: step budget used up"; for (let step = 1; step <= MAX_STEPS; step++) { const p = model(history); if (p.done) { status = (await verify()) ? "verified" : "model said done, check failed"; log(`step ${step}: done -> ${status}`); break; } let result = policy[p.tool] === "allow" ? tools[p.tool](p.args) : `denied by policy: ${p.tool}`; if (result.length > MAX_RESULT_CHARS) result = result.slice(0, MAX_RESULT_CHARS) + " [cut]"; history.push({ ...p, result }); // what the model sees on its next call log(`step ${step}: ${p.tool} -> ${result}`); } console.log(readFileSync("progress.log", "utf8") + "status: " + status);
We ran it with node harness.mjs (Node 22.9) and bun harness.mjs (Bun 1.2). Output:

step 1: read -> export const total = (a, b) => a - b; step 2: shell -> denied by policy: shell step 3: edit -> wrote src/price.js step 4: done -> verified status: verified
Swap the stub for a real model call and the rest stays. The force push was refused by a table in code, not by a sentence in the prompt.

## Should you build your own harness or use an existing one?

Start with an existing harness when the work looks like coding or file work: reading, editing, running commands. Deep Agents and the Claude Agent SDK already ship tools and context handling for that, and the [Agent SDK docs](https://code.claude.com/docs/en/agent-sdk/overview) list Claude Code's permissions, sessions and hooks among its features.

Build your own when the tools are your business systems, when permissions must follow your access model, or when every run needs an audit trail your team controls. Many teams do both: an existing harness for engineering work, a thin custom one for a product feature.

## What should you check before trusting a harness in production?

1. **Permissions live in code.** Deny and ask rules are enforced by the harness, never only described to the model.
1. **Every run has a budget.** Steps, tokens and money, with a clear status when a limit stops the run.
1. **Done means verified.** A test or evaluator the agent cannot edit decides whether the work passes.
1. **State survives a fresh session.** Progress notes and commits let a new context pick up the work.
1. **Components are re-tested on model upgrades.** Each one encodes an assumption that may no longer hold.

For the build steps around a harness, see our guide on [how to build AI agents](https://sdclabs.com/blog/how-to-build-ai-agents/) . SDCLabs builds [AI agents](https://sdclabs.com/services/ai-agents/) this way: senior engineers set the harness rules, agents do the drafting, and automated tests verify every change.

## Sources

1. [Harness design for long-running application development](https://www.anthropic.com/engineering/harness-design-long-running-apps) , Anthropic, 2026-03-24
1. [Effective harnesses for long-running agents](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents) , Anthropic, 2025-11-26
1. [Harness engineering: leveraging Codex in an agent-first world](https://openai.com/index/harness-engineering/) , OpenAI, 2026-02-11
1. [Runtimes, frameworks, and harnesses](https://docs.langchain.com/oss/python/concepts/products) , LangChain, 2026-11-16
1. [Agent SDK overview](https://code.claude.com/docs/en/agent-sdk/overview) , Anthropic, 2026-11-12

## Frequently asked questions

### Is an agent harness related to Harness, the software delivery company?

No. In AI engineering, a harness is the runtime code around a language model. Harness is also the name of a CI/CD software company, which is unrelated.

### Is Claude Code an agent harness?

Effectively, yes. Anthropic calls the Claude Agent SDK, which runs the Claude Code binary with the same tools, agent loop and context management that power Claude Code, a general-purpose agent harness. LangChain's docs list the Claude Agent SDK, Manus and other coding CLIs as examples of agent harnesses.

### What is harness engineering?

It is the work of designing and maintaining the harness: permissions, docs the agent reads, checks, linters and feedback loops. OpenAI used the term in February 2026 for a product its team built with Codex and no hand-written code.

### Does a better model make the harness unnecessary?

It makes some parts unnecessary. When Opus 4.6 shipped, an Anthropic engineer removed the sprint structure from the harness, but kept the planner and the evaluator because they still improved results.

Services

- [AI agents](https://sdclabs.com/services/ai-agents/)
- [AI-Enabled Engineering](https://sdclabs.com/services/ai-enabled-engineering/)

Read next

- [How to build AI agents that still work after the demo](https://sdclabs.com/blog/how-to-build-ai-agents/)
- [What is agentic engineering? How engineers ship software with supervised AI agents](https://sdclabs.com/blog/agentic-engineering/)

Related terms

- [Agentic coding](https://sdclabs.com/glossary/agentic-coding/)
- [Agent observability](https://sdclabs.com/glossary/agent-observability/)

[Mykhailo Poliarush](https://sdclabs.com/author/poliarush/) Founder and CEOLeads SDCLabs, an AI development company founded in Krakow in 2011.[LinkedIn](https://www.linkedin.com/in/poliarush/) [GitHub](https://github.com/poliarush)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
