Build

11 Harness Engineering Projects [With Code]

Explore 11 harness engineering projects with code: build agent loops, tools, sandboxes, evals and guardrails in Python. Free, offline, with tests.

Abhishek Ashtekar holding a folder of project cards beside 11 Harness Engineering Projects text.
On this page
  1. The 11 harness engineering projects at a glance
  2. One running example ties the projects together
  3. How every project works
  4. Which project should you start with?
  5. The 11 projects, one by one
  6. 1. Build an Agent Loop from Scratch
  7. 2. Design Tools an Agent Can Use
  8. 3. Permissions and a Sandbox
  9. 4. Make Work Survive Across Sessions
  10. 5. Loop Controls That Stop for a Reason
  11. 6. Guides and Sensors
  12. 7. Read Traces and Diagnose Failures
  13. 8. Build an Eval Kit
  14. 9. A Graph Workflow with Human Approval
  15. 10. Run, Ablate and Improve a Full Harness
  16. 11. A Harness for a Support Agent That Moves Money
  17. Turn finished projects into portfolio evidence
  18. Frequently asked questions
  19. Learn the ideas behind each project
  20. Final thoughts
  21. Sources and further reading

In brief

The best harness engineering projects build one part of an agent harness at a time and prove it with tests. My free companion course has 11 Python projects, from a 30-line agent loop to a refund agent with four guardrail layers. Each project runs offline with a scripted model, so you need Python 3.10 or newer, a terminal and no API key.

Reading about harnesses will only take you so far. At some point you have to write the code that says no to an agent and watch what happens. These harness engineering projects let you do that, whether you use Claude Code, Codex or Cursor or build your own agents.

The table below shows you all eleven at once. After it, I explain how each project works and where you should begin, and then take you through them one by one. The details come from the course project pages and the course repository README.

The 11 harness engineering projects at a glance

The table lists every project with the harness part it builds and the time the project page gives. The course splits a harness into eight parts, such as Boundaries (where the agent runs and what it may touch) and Checking (how the harness judges its work).

# Project What you build Harness part Time
1 Build an Agent Loop from Scratch The whole loop in about 30 lines Foundations 45 min
2 Design Tools an Agent Can Use Tools that search, cap output and fail with instructions Capability 60 min
3 Permissions and a Sandbox Deny-first rules, a path guard and a Docker sandbox Boundaries 75 min
4 Make Work Survive Across Sessions A feature list, a resume routine, checkpoints and rollback Continuity 75 min
5 Loop Controls That Stop for a Reason Budgets, repeat detection, backoff and a circuit breaker Control flow 60 min
6 Guides and Sensors A lint rule written for an agent and the hooks that run it Correction 60 min
7 Read Traces and Diagnose Failures Trace analysis code and four diagnoses Visibility 75 min
8 Build an Eval Kit pass@k, pass^k, confidence intervals and a judge Checking 75 min
9 A Graph Workflow with Human Approval A small graph engine with interrupts, then LangGraph Control flow 90 min
10 Run, Ablate and Improve a Full Harness Remove one part at a time, measure, then improve All eight 2 to 4 h
11 A Harness for a Support Agent That Moves Money Four guardrail layers against a prompt injection Beyond coding 75 min

If you do all eleven, set aside about 13.5 to 15.5 hours. The README says 30 to 40 hours for the full course, because that figure includes 18 lessons, which take about 14 hours to read.

The course order differs a little from the project numbers. It follows nine parts, so the projects come in this order: 1, 2, 3, 4, 8, 7, 6, 5, 9, 10 and 11.

One running example ties the projects together

Several projects share one story, so you get to know it well. A coding agent adds a weekly streak to a habit-tracker app. The README shows what happens when there is no harness around it. The agent writes its date logic with .date(), edits a shared config file, runs only its own tests and reports that the work is done. A week later, users in Tokyo lose their streaks.

You could blame the model, but a stronger one would have failed in the same place. Nobody had told it about the time-zone helper, it was allowed to write to the config folder, and nothing checked its work independently. Each project closes one of those gaps. If you would like the ideas first, read the worked streak-bug example and come back.

How every project works

Every project uses the same folder layout and the same two test runs, so you learn the routine once. Each folder has an exercise/ directory, a solution/ directory and a pytest file. The exercise files mark the code you write with TODO.

Set up once:

  1. Clone the repository and open the harnesslab folder.
  2. Install the package with its development extras.
  3. Run the demo.
bash
git clone https://github.com/AbhishekAshtekarDev/harness-engineering.git
cd harness-engineering/harnesslab
python -m pip install -e ".[dev]"
python -m harnesslab demo

In the demo, a scripted agent makes the mistakes real agents make, and the harness catches each one.

Then open a project folder and run the tests two ways:

bash
cd ../projects/05-loop-controls
python -m pytest -q
SOLUTION=1 python -m pytest -q

The first command tests your code in exercise/ and fails until you finish the TODOs. The second command tests the reference solution. Read the tests first, because they define the expected behaviour, and compare with the reference only after you pass.

An API key is optional. The course supports Claude and any OpenAI-compatible server, and the OPENAI_BASE_URL setting lets you use a local model server.

Which project should you start with?

Start with the project that matches your background or the failure you see today. The first three rows come from the course README. I added the fourth row for readers who are new to agents.

Your background Start with Then do
New to agents, comfortable with basic Python Project 1 Projects 2 and 5, then the course order
Daily user of Claude Code, Codex or Cursor Project 3 Projects 6 and 7, then write a short AGENTS.md
Engineer building agents from scratch Project 1 All 11, in the course order
Team lead adopting agents Project 7 Project 8, then the Project 10 ablation as a team exercise

If an agent already fails, choose by symptom:

  • An agent that repeats the same command points to Project 5.
  • An agent that says "done" too early points to Projects 4 and 8.
  • An agent that edits files outside its scope points to Project 3.
  • An agent that misuses tools points to Project 2.

My guide to why AI agents fail maps ten common symptoms to the harness part that causes them.

For five more project briefs, use the 5 Hands-On Harness Engineering Projects PDF in my free resource pack.

The 11 projects, one by one

You can read these in any order. Commands start in the repository root unless I say otherwise.

1. Build an Agent Loop from Scratch

You begin with the whole agent loop, which turns out to be about 30 lines. It sends the model the task and the tool descriptions, runs whatever the model asks for and sends the results back, until the model stops asking. In exercise/mini_agent.py, you write execute_tool and run_agent.

It looks almost too small, and that is why it comes first. Every control you build later has a place in this loop. Permissions sit before a tool runs, verification sits where the model stops, and budgets wrap around everything. You also learn to turn an unknown tool or a crash into an error that the model can read.

Open projects/01-agent-loop and run python -m pytest -q. It takes about 45 minutes, and you are done when all five tests pass and you can explain why the loop owns the max_turns limit. If you have an API key, install anthropic or openai, run cd exercise && python run_real.py anthropic, and check in the transcript whether the model ran the file before it claimed success.

Open project 1 on the course site

2. Design Tools an Agent Can Use

Here you are given two bad tools for a small online shop. One of them, get_orders, dumps every order as raw JSON full of UUIDs. The other, refund, wants an internal UUID and answers Error 400. You replace them with search_orders and refund_order, and you soon see why the agent was struggling.

A model chooses a tool by reading its description and decides what to do next by reading its output. So you learn to check the inputs, keep the output short and write errors that tell the agent how to recover. It makes a real difference. Anthropic's article on writing effective tools for agents reports that refining tool descriptions helped Claude Sonnet 3.5 reach a state-of-the-art score on SWE-bench Verified.

Open projects/02-tool-design, write the two tools in good_tools.py and run python -m pytest -q. Read the two *_SPEC dictionaries to see how each parameter gets its description. Give it about an hour. When all eight tests pass, your output will be at least 20 times smaller than the bad tool's, with no UUIDs, and every error will say what to do next.

Open project 2 on the course site

3. Permissions and a Sandbox

In exercise/guard.py, you write four guards. The decide function applies allow, ask and deny rules, and a matching deny always wins. check_write refuses ../ escapes, absolute paths, symlinks out of the workspace and protected files. scrub_env builds the child environment from an allow-list, and trifecta_report warns you about the lethal trifecta.

The lesson that stays with you is the difference between a rule and a wall. One test, test_rules_are_tripwires_not_walls, passes because a deny rule on git push* does not catch git -C . push. Simon Willison's post on the lethal trifecta explains the danger behind the last guard, which is an agent that has private data, untrusted content and a way to send data out.

Open projects/03-permissions-and-sandbox and run python -m pytest -q. Docker is optional. If you have it, run docker build -t harness-sandbox:latest sandbox/, then run a command through sandbox/run-in-sandbox.sh and check that curl and a write to /etc both fail. After about 75 minutes, with all five tests passing, you should be able to name the boundary that stops a leaked secret, a write to ~/.ssh and a fork bomb.

Open project 3 on the course site

4. Make Work Survive Across Sessions

You build the session pattern from Anthropic's article on effective harnesses for long-running agents. The initialize function writes a JSON list with every feature marked as failing, a progress log and a first checkpoint. start_session then finds the next feature, runs a smoke check and tests again every feature that the records call finished.

You will learn to be suspicious of records. A feature may be marked as passing only after a check has passed, and any edit to the list that changes something else is rejected. If a session crashes, your code notices and rolls back to the last checkpoint.

Open projects/04-long-running-state and read test_sessions.py before you write anything, especially the crash test and the "records that lie" test. Then run python -m pytest -q. It takes about 75 minutes. With all six tests passing, the next session detects a crash in the middle of a feature and rolls it back, and it catches a hand-edited list that claims an unbuilt feature works.

Open project 4 on the course site

5. Loop Controls That Stop for a Reason

An agent that cannot stop is expensive, so in exercise/controls.py you write the exits. stop_reason checks budgets for iterations, tokens, time and cost. It also notices runs with no progress, repeated actions and A-B-A-B oscillation. You then add classify_failure, capped exponential backoff, a circuit breaker and should_trigger.

The most useful thing you take away is how to tell a temporary error, which deserves another try, from a real one, which needs a new approach. should_trigger teaches something subtler. It stops an event loop from reacting to events that its own agent caused.

Open projects/05-loop-controls and run python -m pytest -q after each function. When you finish, compare your code with harnesslab/harnesslab/loop.py, which uses the same ideas in a complete harness. Allow about an hour. You are done when all seven tests pass and you can say which kind of runaway each control prevents.

Open project 5 on the course site

6. Guides and Sensors

In this one, you write a lint check for an agent to read, and two hooks that run it. lint_source uses Python's ast module, so it never mistakes a comment or a string for code. Rule HT001 flags .date() on a datetime, and HT002 flags a clock read without a time zone. You also write post_edit_hook and on_read_hook.

Think about two messages. One says HT001 violation. The other says what is wrong, why it matters and how to fix it. The agent can act on the second one in its next step, and that is the whole idea of the project. A good hook stays silent when the work is fine and speaks clearly when it is not.

Open projects/06-guides-and-sensors and run python -m pytest -q. Afterwards, compare your check with the regex version in harnesslab/harnesslab/presets.py. If you want to go further, the stretch goal registers your lint as a Claude Code PostToolUse hook. It takes about an hour, and you are finished when all five tests pass and each finding explains the problem, the reason and the fix.

Open project 6 on the course site

7. Read Traces and Diagnose Failures

Now you become a detective. The traces/ folder holds four recorded runs of the habit-tracker harness, and each one contains a failure. In exercise/trace_analysis.py, you write four functions to help you look. They are summary, edits_per_file, which shows a stuck loop, first_problem, which tells you where to begin, and files_read, which shows what the agent saw.

You learn to read the evidence before you change anything. You diagnose runs A to D in DIAGNOSIS.md with the course's five questions and then compare your answers with solution/ANSWERS.md.

To look at one trace, go to the harnesslab/ folder and run python -m harnesslab trace ../projects/07-traces-and-diagnosis/traces/run-b.jsonl. Then open projects/07-traces-and-diagnosis and run python -m pytest -q. In about 75 minutes, you should have all five tests passing and, for each run, a name for the failure, the part of the harness at fault and the cheapest fix.

Open project 7 on the course site

8. Build an Eval Kit

One good demo tells you very little, and this project shows you how little. In exercise/evalkit.py, you write pass_at_k, pass_pow_k, a Wilson confidence interval and a compare function that is willing to say "inconclusive". A pairwise judge asks its question in both orders to cancel position bias, and cohen_kappa measures how often the judge agrees with a person.

Look at what happens in the sample output. A careful agent passes 9 of 10 trials, and a hasty one passes 6. On pass@3 they seem almost equal, at 1.00 and 0.97. On pass^3, the careful agent scores 0.70 and the hasty one 0.17. Anthropic's guide to evals for AI agents explains why. The first needs one success in k tries, and the second needs all of them.

Open projects/08-evals and run python -m pytest -q. Then run cd exercise && python run_suite.py --trials 10, follow it with --trials 40, and watch the confidence intervals narrow. It takes about 75 minutes. When all five tests pass, you can explain why the two agents look alike on one number and so different on the other.

Open project 8 on the course site

9. A Graph Workflow with Human Approval

You write a small graph engine in exercise/minigraph.py, with nodes, edges, routers, reducers, a step limit and checkpoints that let it pause and resume. On top of it, workflow.py plans, builds, tests, reviews and asks for approval before it opens a pull request. If three cycles fail, it hands the work to a person.

By building the engine yourself, you see how a graph stores its state, waits for someone and carries on. The reference solution then does the same job on LangGraph (tested with version 1.2), so you can compare your own work with a production framework.

Open projects/09-graph-workflow and run python -m pytest -q. The LangGraph test runs only if you have installed langgraph. Then run cd solution && python langgraph_version.py and watch a run stop for approval. Plan for about 90 minutes. You are done when the tests pass and you can point to the place where your engine and LangGraph each keep the state they need to resume.

Open project 9 on the course site

10. Run, Ablate and Improve a Full Harness

This is the capstone. You take the complete habit-tracker harness in harnesslab, with its workspace, path guard, deny-first policy, hooks, verification, budgets and tracing, and you remove one part at a time. For each run, the ablation script shows what the agent claimed, what the harness concluded and what an independent audit found.

You finish with evidence about which part catches which mistake. If you have an API key, you can go further by finding the most common real failure, making the smallest fix and proving it with runs before and after. Report your sample size each time, because a few runs rarely prove much.

Run python -m harnesslab demo from the harnesslab folder. From the repository root, run python projects/10-capstone-full-harness/ablation.py. With a key, run python -m harnesslab run --provider anthropic (or openai) at least three times. Set aside two to four hours. You have finished when you can show at least three real runs on each side of your change, and your harness spec fits on one page.

Open project 10 on the course site

11. A Harness for a Support Agent That Moves Money

The last project leaves coding behind. You protect a support agent that can issue refunds, using four layers. The input guardrail sends messages aimed at the AI, or floods of text, to a person. scan_untrusted holds back instructions hidden in order notes. The refund guard checks five business rules, and the output guardrail blocks other customers' emails, promises and refunds that never happened.

In one scripted conversation, a planted note fools the model into trying to refund someone else's $900 order. The model asks for it, and your code says no. It is a good moment, because you see that the same harness parts work far outside software.

Open projects/11-support-agent-harness and run python -m pytest -q. Then run cd exercise && python support_agent.py and read how each of the four conversations ends. It takes about 75 minutes. When all six tests pass, no money moves in the injection scenario. This is a teaching environment, so a real payment system will need its own security review.

Open project 11 on the course site

Turn finished projects into portfolio evidence

A project becomes part of your portfolio when another engineer can check it in a few minutes. For each one you publish, write a short README with these things in it:

  1. The task and the control you built.
  2. One failure the control catches.
  3. The command that proves it.
  4. The limits of what you tested.
  5. One short trace or test output that a reviewer can read.

Show what your agent does when something goes wrong. A blocked git -C . push, a session that resumes after a simulated crash or a pass^3 comparison proves that you understand why a control exists, and a list of frameworks does not. The code uses the MIT licence and the course content uses CC BY 4.0, so keep the notices when you publish your version.

If you would like a plan for doing all of this in a month, my 30-day harness engineering roadmap places the projects week by week. The guide on how to test AI agents will help you decide what to measure.

Frequently asked questions

These are the questions developers ask about agent projects in course FAQs, beginner project guides and developer forums. For questions about testing and safe agents, see how to make agents reliable and safe.

1. Do I need an API key to do these projects?

No. Each exercise, each test and the harnesslab demo run offline with a scripted model. If you have a key from Anthropic or an OpenAI-compatible provider, you can repeat some projects on a real model, and the capstone is the best place to do it.

2. Do I need LangChain or another framework to learn how agents work?

You do not. The projects use plain Python, and you write the whole agent loop in about 30 lines in Project 1. You meet LangGraph in Project 9, where you compare it with an engine you have already built.

3. What should I build first to learn AI agents?

Build the agent loop first. Project 1 takes about 45 minutes, and the later projects all connect to it. If you would like someone to walk you through it, the harness engineering tutorial builds a small agent step by step.

4. How long do the harness engineering projects take?

Plan for about 13.5 to 15.5 hours of hands-on work for all eleven. The full course, with its 18 lessons, takes 30 to 40 hours. If you use a coding agent every day, the README also has a shorter path that fits into an afternoon.

5. I only use Claude Code or Cursor. Are these projects useful for me?

They are. Claude Code, Codex and Cursor each come with a harness, and your own instruction files, rules, hooks and tests wrap around it. Try Project 3 for permissions and Project 6 for hooks, and then use the same ideas in your own setup.

6. Are the projects free, and can I publish my solutions?

Yes to both. The code has an MIT licence and the lessons use CC BY 4.0, so you can publish your version if you keep the licence notices. You will only pay if you choose to run a real model.

7. Will these projects help my portfolio?

They will help if you show what your agent does as well as the code. A blocked command, a session that resumes after a crash or a pass^k table tells a reviewer far more than a list of tools.

8. What do I need to know before I start?

You should know Python 3.10 or newer, be comfortable with functions and files, and be able to run pytest in a terminal. You do not need machine learning. Docker is optional for Project 3, and so is LangGraph for Project 9.

9. Is harness engineering only for coding?

No. Support, research and document agents need the same parts. In Project 11, you protect a support agent that can issue refunds. A research agent needs its claims checked against its sources, so that you know whether the cited page supports the sentence.

Learn the ideas behind each project

A project shows you how a control behaves. It does not always tell you when you need that control or what happens to the rest of the system when you add it. I wrote The Harness Engineering Blueprint to answer those questions, and I built the free companion course alongside it, so I am not neutral. In my view, it is the best book to learn harness engineering, and it goes well with these 11 projects.

You can compare it with other books on the subject before you decide.

Final thoughts

Harness engineering projects teach you something that reading cannot. You watch a control fail, you fix it, and a test tells you whether you were right. Clone the repository today, run the demo and finish Project 1.

After that, choose the project that matches your agent's worst habit. If you are also choosing tools for your own setup, my comparison of harness engineering tools shows where each one fits. And if you would like a teacher beside you, here are ten courses worth looking at.

Sources and further reading