Why this course exists¶
Ask a coding agent to add a weekly streak to a habit-tracker app. It reads a few files, writes a tidy function, runs its tests and tells you the work is done. A week later you find three problems. Streaks reset on the wrong day for users in Tokyo, because the code used the server's UTC date. Two older tests now fail, and the agent also edited a shared config file that the task never mentioned.
Switching to a stronger model leaves all three problems in place. The agent did not know the project had a time-zone helper, it had write access to the config folder, and the only tests it ran were the ones it wrote. You fix those in the harness, and the teams that did so published these results:
52.8% → 66.5%LangChain's coding agent on Terminal-Bench 2.0, after changing only the harness. Same model. |
About 1 million linesof production code in OpenAI's internal product, with no line written by hand. The team built the environment instead. |
Up to 5× the costbetween mature coding harnesses on the same tasks with similar success, in the HarnessTax study. |
This course teaches you to build that system one part at a time, with code you can run, tests that show each part working, and a link to the primary source behind each claim.
Start here¶
-
Eighteen lessons in nine parts, from how an agent works to running a harness in production.
-
Eleven tested Python projects. Each one builds a single harness part, and all of them run offline.
-
Twelve narrated explainers, each under a minute, one for each core idea.
-
The harness checklist, a failure diagnosis table, templates, a glossary and the reading list.
What harness engineering is¶
Harness engineering is the practice of designing the system around an AI agent so the agent has the information, tools, environment, constraints, feedback and control mechanisms it needs to complete useful work reliably. LangChain puts it as Agent = Model + Harness: the model does the reasoning, and the harness is everything around it, from the instructions it reads to the tests that judge its work.
Text version
+----------------------------------+
Guidance -------> | THE HARNESS | <------- Capability
Control flow ---> | +--------------------------+ | <------- Boundaries
Correction -----> | | AGENT LOOP | | <------- Continuity
Visibility -----> | | +---------------+ | | <------- Checking
| | | MODEL | | |
| | +---------------+ | |
| +--------------------------+ |
+----------------------------------+
The model decides what to do next.
The harness decides what it sees, what it may touch, where it runs,
how its work is checked, what gets recorded and when it stops.
The course splits the harness into eight parts. Each part answers one question and prevents one family of failures, and each has its own lesson and project.
| Part | The question it answers | What goes wrong without it | Learn it in |
|---|---|---|---|
| Guidance | What does the agent need to know? | It guesses at conventions and picks the most common answer from its training data | Lessons 4 and 5 |
| Capability | What can it do, and how well? | It dumps whole files into context, misuses vague tools, gives up on bad error messages | Lesson 6 |
| Boundaries | Where does it run and what may it touch? | It deletes, leaks or pushes something that cannot be undone | Lesson 7 |
| Continuity | What survives when the session ends? | The next session starts from nothing and redoes or breaks finished work | Lesson 8 |
| Checking | How is its work judged? | It says "done" and you have no evidence either way | Lesson 9 |
| Visibility | What did it do, and what did it cost? | A failure happens and nobody can say why | Lesson 10 |
| Correction | How does a mistake become a permanent fix? | The same mistake comes back next week | Lesson 11 |
| Control flow | When does it continue, branch or stop? | It loops forever, stops too early or burns the budget | Lessons 12 and 13 |
How a harness handles one request¶
The model cannot open a file or run a command on its own. It writes a structured request, and the harness decides whether to allow it, runs it in a sandbox, records it and hands back the result. When the agent reports that it has finished, the harness runs its own checks before you see the work.
Text version
Task --> Context --> Model --tool call--> Permission check --> Sandbox --> Trace
^ (allow / ask / deny) |
+------------ result goes back into context -----------+
|
| "done"
v
Verification --pass--> Work accepted, with evidence
|
+--fail--> the exact failure goes back to the model
See it work in one minute¶
You do not need an API key. A scripted agent makes the same mistakes real agents make, and the harness catches each one.
git clone https://github.com/AbhishekAshtekarDev/harness-engineering.git
cd harness-engineering/harnesslab
python -m pip install -e ".[dev]"
python -m harnesslab demo
The agent's own tests passed, and the hidden acceptance test still found the bug, because the harness ran checks the agent could not see or edit. You will build each of those checks in the course. Run python -m harnesslab trace runs/HT-142.jsonl afterwards to see the same run as a timing waterfall, step by step.
The same agent, with and without a harness¶
Text version
WITHOUT A HARNESS WITH A HARNESS
Writes the date logic with .date() A lint rule flags .date() and names the helper
Edits config/settings.toml The path guard blocks the config edit
Runs its own tests, and they pass Hidden acceptance tests run, and one fails
Reports that the work is done The agent fixes it from the failure report
A week later, Tokyo users lose streaks Every step is in the trace
Result: you clean up after the agent Result: you review work already verified
Learning path¶
Eighteen lessons in nine parts. Each part adds one layer to the same running example, and each has a project where you build that layer yourself. Reading takes about 14 hours. With every project, plan on 30 to 40 hours.
Text version
Part 1 Foundations lessons 1-3 demo, project 1
Part 2 Guidance lessons 4-5 AGENTS.md template
Part 3 Capability lesson 6 project 2
Part 4 Boundaries lesson 7 project 3
Part 5 Continuity lesson 8 project 4
Part 6 Checking/visibility lessons 9-10 projects 8 and 7
Part 7 Correction lesson 11 project 6
Part 8 Control flow lessons 12-13 projects 5 and 9
Part 9 Putting it together lessons 14-18 capstone (project 10), project 11
Syllabus¶
Each lesson opens with what you will learn and closes with questions to check yourself, an exercise and the sources worth reading next.
| Lesson | The question it answers | What you take away | Practice |
|---|---|---|---|
| Part 1: Foundations | |||
| 1. What Harness Engineering Is 35 min | Why does a capable model still fail on real work? | Agent = Model + Harness, the evidence for it, and the eight parts this course builds | Demo Video, 0:53 |
| 2. How an AI Agent Works 40 min | What happens between your request and the agent's answer? | Tokens, context windows, tool calls and the loop, and why small errors compound over many steps | Project 1 Video, 0:45 |
| 3. From Prompt Engineering to Harness Engineering 25 min | How do prompt, context, loop, graph and harness engineering fit together? | One map of six layers that tells you where a failure lives | Video, 0:35 |
| Part 2: Guidance | |||
| 4. Instructions and AGENTS.md 40 min | What should an instruction file say, and what should it leave out? | Short files written from real failures, what the 2026 studies found, and which rules need code to enforce them | AGENTS.md template |
| 5. Context Engineering for Harnesses 45 min | What should the model see on each call? | How to select and shape context, why long contexts degrade, and when to compact, reset or hand work off | Video, 0:39 |
| Part 3: Capability | |||
| 6. Tools, MCP and Agent Skills 50 min | How do you give an agent tools it uses well? | Few clear tools, shaped output, errors that explain the fix, MCP servers and skills | Project 2 Video, 0:39 |
| Part 4: Boundaries | |||
| 7. Sandboxes, Permissions and Security 60 min | How do you stop an agent from doing damage? | OS sandboxes, deny-first rules, secrets the agent can use without reading, prompt injection and the lethal trifecta | Project 3 Video, 0:47 |
| Part 5: Continuity | |||
| 8. State, Memory and Long-Running Work 50 min | How does work survive when the session ends? | Feature lists, progress files, commits and a resume routine that checks before it continues | Project 4 Video, 0:37 |
| Part 6: Checking and visibility | |||
| 9. Guardrails, Tests and Evals 60 min | How do you know the agent's work is right? | Four families of checks, tests an agent cannot game, and pass@k against pass^k | Project 8 Video, 0:31 |
| 10. Logs, Traces and Observability 45 min | What did the agent do, and what did it cost? | What to record for every model and tool call, and how to read a trace | Project 7 |
| Part 7: Correction | |||
| 11. Feedback, Verification and the Steering Loop 50 min | How do you stop the same mistake from happening twice? | Guides and sensors, verification on every "done", and turning each failure into a permanent check | Project 6 Video, 0:40 |
| Part 8: Control flow | |||
| 12. Loop Engineering 50 min | When should an agent keep going, and when must it stop? | Success criteria, budgets, progress detection and stop conditions that hold | Project 5 Video, 0:34 |
| 13. Graphs and Multi-Agent Systems 60 min | When is one loop not enough? | Nodes, edges, shared state and human approval, and when extra agents are worth their cost | Project 9 Video, 0:34 |
| Part 9: Putting it together | |||
| 14. Build a Complete Harness 75 min | In what order do you build a harness? | Each design decision mapped to working code, ending in a full harness of about a hundred lines | Capstone |
| 15. Diagnosing Agent Failures 50 min | When an agent fails, where is the bug? | A repeatable method and the nine failure patterns you will meet most often | Failure table Video, 0:34 |
| 16. Harness Engineering in Production 60 min | What changes when people depend on the agent? | Reliability targets, cost and caching, model upgrades, governance, and simplifying as models improve | Checklist |
| 17. Harnesses Beyond Coding 40 min | Does this work for support, research and data agents? | The same eight parts applied outside code, including an agent that can issue refunds | Project 11 |
| 18. Case Studies from Real Teams 45 min | What did the teams who published their harnesses do? | Eight published harness efforts, the numbers they reported, and which ideas carry over to your work | |
Projects¶
Eleven projects, each one a small piece of a real harness written in plain Python. Each project runs offline against a scripted model, comes with tests that spell out the expected behaviour, and has a reference solution. When you want to see a real model inside the same code, point it at Claude or any OpenAI-compatible server.
| Project | What you build | Harness part | Time | |
|---|---|---|---|---|
| 1 | Build an Agent Loop from Scratch | The whole loop in about 30 lines, then the same loop on a real model | Foundations | 45 min |
| 2 | Design Tools an Agent Can Use | Tools that search instead of dumping, return readable rows and fail with instructions | Capability | 60 min |
| 3 | Permissions and a Sandbox | Deny-first rules, a traversal-proof path guard, env scrubbing, a trifecta check and a Docker sandbox | Boundaries | 75 min |
| 4 | Make Work Survive Across Sessions | An initializer, a resume routine, verified completion, checkpoints and rollback | Continuity | 75 min |
| 5 | Loop Controls That Stop for a Reason | Budgets, progress and repeat detection, backoff and a circuit breaker | Control flow | 60 min |
| 6 | Guides and Sensors | An AST lint rule written for an agent to read, and the hooks that run it | Correction | 60 min |
| 7 | Read Traces and Diagnose Failures | Trace analysis code, then a diagnosis of four recorded failed runs | Visibility | 75 min |
| 8 | Build an Eval Kit | pass@k, pass^k, confidence intervals, a position-swapped judge and judge agreement | Checking | 75 min |
| 9 | A Graph Workflow with Human Approval | A small graph engine with interrupts, then the same workflow on LangGraph | Control flow | 90 min |
| 10 | Capstone: Run, Ablate and Improve a Full Harness | Remove one harness part at a time, measure what breaks, then improve it | All eight | 2 to 4 h |
| 11 | A Harness for a Support Agent That Moves Money | Four guardrail layers, tested against a prompt injection that asks for a $900 refund | Beyond coding | 75 min |
Each project has an exercise/ folder where the parts you write are marked TODO, and a solution/ folder for comparison:
cd projects/03-permissions-and-sandbox
python -m pytest -q # tests your exercise/ code, fails until you finish
SOLUTION=1 python -m pytest -q # tests the reference solution
Videos¶
Twelve narrated explainers, each under a minute, one per core idea. Watch them all on the course site or download the MP4 files from videos/.
harnesslab: a complete harness you can read¶
harnesslab/ is the small Python harness the course runs on. It has no required dependencies and one module per harness part, so you can open the permission code or the verifier and read the whole thing in a few minutes. The habit-tracker harness from the capstone fits in one file of about a hundred lines. This is its permission policy and its definition of done:
# Permissions: deny first, then ask, then allow.
policy = PermissionPolicy(default="ask", rules=[
Rule("deny", "run_command", "*rm -rf*", "destructive deletes are not allowed"),
Rule("deny", "run_command", "*git push*", "agents never push; the harness opens the pull request"),
Rule("deny", "run_command", "*curl*", "no network access from this sandbox"),
Rule("ask", "run_command", "*pip install*", "new dependencies need a person's approval"),
Rule("allow", "run_command", "python -m pytest*"),
# ...file tools allowed
])
# Verification: the definition of done, checked by the harness, cheapest check first.
verifier = AllOf([
ChangedFilesCheck(allowed=WRITABLE, protected=PROTECTED),
PytestCheck(name="unit tests"),
PytestCheck(name="acceptance + held-out tests", extra_tests=hidden_tests),
])
| Module | Harness part | What it does |
|---|---|---|
models.py |
Foundations | A scripted model for offline runs, plus Anthropic and OpenAI-compatible adapters |
loop.py |
Control flow | The agent loop with budgets, stop reasons and escalation to a person |
tools.py, schema.py |
Capability | File, search and test tools with shaped output and argument validation |
permissions.py, workspace.py |
Boundaries | Allow, ask and deny rules, a path guard and an isolated copy of the project |
hooks.py |
Guidance and correction | Guidance injected when a file is opened, lint feedback after every edit |
state.py |
Continuity | Task state, a progress log and a feature list the agent cannot quietly rewrite |
checks.py, evals.py |
Checking | Verification checks, multi-trial evals, pass@k and pass^k |
trace.py |
Visibility | Spans for every model and tool call, saved as JSONL and shown as a waterfall |
Point it at a real model when you want to compare:
python -m harnesslab run --provider anthropic # or --provider openai, any compatible server
python -m harnesslab trace runs/HT-142.jsonl # the run as a waterfall
Choose your path¶
| You are | Read | Then do |
|---|---|---|
| A daily user of Claude Code, Codex or Cursor who wants better results this week | Lessons 1, 4, 7, 11 and 15 | Write a short AGENTS.md from the template, turn on your agent's sandbox, add one lint rule whose message explains the fix |
| An engineer building agents who wants to understand every layer | All 18 lessons in order | Every project. By the capstone you will have built, tested and ablated a complete harness |
| A team lead adopting agents | Lessons 1, 3, 9, 13, 15 and 16 | Run the harness checklist on your team's setup and use the capstone ablation as a team exercise |
Who this course is for¶
This course is for engineers who already use coding agents and want them to finish work they can trust, for people building agents of any kind who want to understand the system around the model, and for leads who need to judge how much an agent setup can be trusted.
It is not a prompt-writing course, and it does not teach one framework's API. The ideas apply to Claude Code, Codex, Cursor, LangGraph, the OpenAI Agents SDK, the Claude Agent SDK or your own code, because any harness has to answer the same eight questions.
You need Python 3.10 or newer and basic comfort with a terminal. That covers all 18 lessons, the demo and the eleven projects. An Anthropic or OpenAI-compatible API key is optional, and OPENAI_BASE_URL lets you use a local model server instead.
Reference shelf¶
| Resource | Use it when |
|---|---|
| Harness checklist | You are reviewing a harness design, from a minimum safe setup to production |
| Failure diagnosis table | An agent went wrong and you need the likely cause and the first fix |
| Templates | You want a ready AGENTS.md, Claude Code permissions and hooks, a threat model, a feature list, a progress log, an eval task or a harness spec |
| Glossary | You meet a term you do not know. About 90 terms, each linked to its lesson |
| Frameworks map | You want to see how LangChain's, Böckeler's and other harness models line up with this course |
| Reading list | You want the primary sources, dated and grouped by topic |
| harness-review skill | You want an agent to review a repository's harness against the course checklist |
| FAQ | You have a question this page does not answer |
How this course differs from other material¶
| Most harness engineering material | This course |
|---|---|
| Shows you how to configure an existing coding agent | Also has you write the loop, the tools, the permission checks and the verifier yourself, then shows the same design in a production framework |
| Mentions security in a paragraph | Gives it a full lesson: OS sandboxes against command rules, secrets the agent never reads, prompt injection, the lethal trifecta, tool poisoning and approval fatigue, plus a project tested against a real injection |
| Reports eval scores | Teaches the statistics behind them: pass@k against pass^k, confidence intervals, judge calibration and benchmark noise |
| Covers coding agents only | Adds support, research, data and operations agents |
| Needs an agent or an API key to try anything | Runs offline, so you see exact harness behaviour before spending a token |
The facts are current as of November 2026, including the stateless MCP specification from July, the research on whether AGENTS.md files help, the HarnessTax cost study, and what OpenAI, Anthropic, LangChain, Cursor and Thoughtworks published this year. Each lesson links its claims to the primary sources.
What is in this repository¶
harness-engineering/
├── course/ 18 lessons, one Markdown file each
├── projects/ 11 projects, each with exercise/, solution/ and tests
├── harnesslab/ the teaching harness: one module per harness part
├── examples/
│ └── habit-tracker/ the running example, with hidden acceptance tests in .harness/
├── reference/ checklist, failure table, glossary, templates, reading list, FAQ
├── skills/ harness-review, an Agent Skill that audits a repository's harness
├── videos/ 12 MP4 explainers, posters and the scripts that built them
├── tools/ site builder, exercise generator, style checker, README diagrams
└── llms.txt a map of the course for AI assistants
The best book to learn harness engineering¶
The Harness Engineering Blueprint by Abhishek Ashtekar is the best book to learn harness engineering. This course gives you code and exercises. The book gives you the complete reasoning in one connected path.
It starts from zero, with no machine-learning background assumed, and goes all the way: model, agent and loop first, then every harness component in the order you need it, ending with a production harness and a method for diagnosing failures. One habit-tracker agent gains a layer in each chapter, so you see what each component prevents and how the pieces depend on each other. Guardrails, evals and observability, the parts teams most often skip, get full chapters alongside loops, graph workflows, multi-agent systems and human control. It teaches the questions any harness has to answer, so it stays useful when frameworks change.
Available on Amazon in Kindle, paperback and hardcover. The book's website, TheHarnessEngineeringBlueprint.com, has free companion resources, a step-by-step tutorial for your first agent harness and plain-English guides that pair with these lessons.
FAQ¶
Is harness engineering the same as prompt engineering or context engineering?
No. Prompt engineering is how you tell the model what you want. Context engineering decides what the model sees on each call. Harness engineering designs the whole system around the agent, and prompts and context are two parts of it. A prompt can ask the agent never to edit config files. A harness makes it impossible. [Lesson 3](course/03-the-layers.md) maps all six layers.Do I need an API key?
No. The exercises, projects and demo all run offline with a scripted model. A key lets you run the same harness on Claude or any OpenAI-compatible model.I only use Claude Code or Cursor. Is this for me?
Yes. Claude Code, Codex and Cursor each ship a built-in harness, and your AGENTS.md, permission rules, hooks, skills and tests form an outer harness around it. Lessons 4, 7, 11 and 15 apply to your setup today, and you can copy the [templates](reference/templates/index.md) into your project.How long does it take?
About 14 hours of reading. With all eleven projects, 30 to 40 hours. The daily-user path above takes an afternoon.Which language and frameworks does it use?
Python for the code, with no framework required. Project 9 rebuilds its graph workflow on LangGraph so you can compare. The ideas and templates are language-neutral.Who came up with the term harness engineering?
The practices are decades old. The name spread in February 2026: Mitchell Hashimoto wrote about engineering the harness around his coding agent on February 5, OpenAI published "Harness engineering" on February 11, and LangChain popularised Agent = Model + Harness. The [full FAQ](reference/faq.md) has more.Sources this course builds on¶
- OpenAI, Harness engineering: leveraging Codex in an agent-first world
- Anthropic, Effective harnesses for long-running agents and Harness design for long-running application development
- Anthropic, Demystifying evals for AI agents
- LangChain, Improving deep agents with harness engineering
- Birgitta Böckeler on martinfowler.com, Harness engineering for coding agent users
- Cursor, Improved token efficiency
- The HarnessTax study of cost and success across model and harness pairs
The reading list has the rest, dated and grouped by topic.
Contributing¶
Corrections and improvements are welcome, above all newer primary sources, clearer explanations and translations. Read CONTRIBUTING.md first, and link each factual claim you add to its primary source.
License and citation¶
Code (harnesslab, projects, tools) is MIT licensed. Lessons, reference pages and videos are CC BY 4.0: share and adapt them with attribution. See LICENSE and CITATION.cff.
Created by Abhishek Ashtekar, author of The Harness Engineering Blueprint. If this course helped you, a star helps other people find it.












