Live on Product HuntThe open source launch of CybeDefendSupport usSupport usStar on GitHub
Star
Back to all posts

Agent Harness Security: What Harness Engineering Leaves Out, Piece by Piece

An agent harness is everything a team adds around a coding agent. The eight pieces of a Claude Code harness, and the security check to add at each one.

On this page
  1. What is an agent harness?
  2. Where does harness engineering come from?
  3. What are the eight pieces of a coding agent harness?
  4. What should each piece of the harness carry for security?
  5. What does a tool call go through before it runs?
  6. Do a team's hooks and a security block collide?
  7. Which settings switch hooks off without a message?
  8. How do you ship security as a block in a harness?
  9. Does the same block exist in other coding agents?
  10. How does CybeDefend secure each piece of a harness?
  11. What is the reason at each piece?
  12. Frequently asked questions
  13. What is an agent harness?
  14. What is harness engineering?
  15. What is agent harness security?
  16. Are Claude Code hooks enough to secure a harness?
  17. Do Claude Code hooks run in headless mode?
  18. Can a developer or a repository disable a security hook?
  19. Where do I start on a harness that already exists?

One coding agent harness read piece by piece, with what security adds at each: the map, kept short, with no secret, reviewed like code; the rules, with your company's rules served for the file being written; the skills, with the full security audit as one command; the sub-agents, with the same guard inside each one; the hooks, with each action checked before it runs; the tools, with rules and findings as tools the agent calls; the permissions, with a refusal that holds with prompts off; the pipeline, with a scan before the pull request and a record

An agent harness is everything a team adds around a coding agent so that it builds the way the team builds: instruction files, rules, skills, sub-agents, hooks, tools, permissions and the script that launches it. Agent harness security is the part of that work that decides what the agent may write and run, and it has a check to add at each of those eight pieces.

Harness engineering is written to make the agent produce. This guide reads the same harness as a security engineer would, piece by piece, and it sits under our guide to AI coding agent security. Every rule quoted here was read in the documentation of the coding agents on 28 November 2026, and each one is linked.

What is an agent harness?

An agent harness is the set of files, programs and settings that surround a coding agent and turn a general model into a member of one team. The model is the same for everybody. The harness is what makes it use your package manager, put tests where you put them, call your internal tools and stop where you want it to stop.

The word is used at two levels. The makers of the agents use it for the program itself: Claude Code is a harness around a model, and its hooks guide says that running your commands at fixed points of its lifecycle "gives you deterministic control". Teams use it for what they add on top. When engineers search for a Claude Code harness, an AI agent harness or a coding agent harness, they are looking for that second layer, the one they write themselves. This guide is about that layer.

Where does harness engineering come from?

The term spread from OpenAI's write-up of 11 February 2026, Harness engineering: leveraging Codex in an agent-first world. Its team describes shipping an internal product "with 0 lines of manually-written code", and sums up the division of work in four words: "Humans steer. Agents execute."

Two lessons from that article shaped how teams build a harness. The first is about the instruction file: "give Codex a map, not a 1,000-page instruction manual." OpenAI treats AGENTS.md as "the table of contents", and not as the encyclopedia. The second is about enforcement. The constraints of the codebase are "enforced mechanically via custom linters (Codex-generated, of course!) and structural tests", and the linter messages are written "to inject remediation instructions into agent context."

That is agent harness engineering doing its job: it keeps the agent productive and the codebase coherent. It answers the question of how to build here. Whether an action is allowed here, in this company, is a second question, and the harness has a place for it at each piece. Once the harness runs unattended, as in the factories we describe in how to secure an AI software factory, that second question has nobody left to answer it by hand.

What are the eight pieces of a coding agent harness?

A coding agent harness comes down to eight pieces. The table gives each one with the place it lives on a project that uses Claude Code, taken from the Claude Code documentation. The other coding agents have the same pieces under other file names.

PieceWhat it doesWhere it lives with Claude Code
The mapA short file that says what the project is and where to lookCLAUDE.md, or AGENTS.md, which Claude Code can read in its place
The rulesHow to code here, sometimes scoped to file paths.claude/rules/
Skills and commandsThe team's method as steps the agent can run.claude/skills/<name>/SKILL.md, and the older .claude/commands/
Sub-agentsSpecialists the main agent calls, a reviewer or a tester.claude/agents/
HooksPrograms Claude Code runs by itself at fixed moments.claude/settings.json, a plugin's hooks/hooks.json, managed settings
ToolsServers the agent can call through MCP.mcp.json
Permissions and sandboxWhat the agent may do without asking, and where it runsSettings files, the container
Orchestration and pipelineThe script or the CI job that launches the agent and checks its workA workflow file, a program on the Agent SDK

Each piece was designed to help the agent produce. Each one also has a security side, and the comparison below puts the two next to each other.

Piece
Written to produce
What security adds
The map
What the project is, where things are
Kept short, with no secret in it, and reviewed like code
The rules
How to code here, written by hand
Your company's own rules, served for the file being written
Skills and commands
Spec, plan, implement, review
Each skill read before it is installed, and the full security audit as one command
Sub-agents
A reviewer, a tester, a planner
The same guard inside each one, with the sub-agent named in the record
Hooks
Format, lint, run the tests
Each file write and each command checked before it runs
Tools
The tracker, the docs, the build
Each server reviewed, and the rules and the findings as tools
Permissions and sandbox
Fewer prompts, an isolated machine
A refusal that still holds when the prompts are off
Orchestration and pipeline
Launch the agent, open the pull request
A scan of the changed files before the pull request, and a record

What should each piece of the harness carry for security?

Each piece carries one security question, and the answer is short enough to check in a review of the harness.

The map

An instruction file is advisory, and anyone who can commit to it steers every agent on the project. Keep it short, keep secrets and tokens out of it, and review a change to it like a change to code. We cover the attack in our article on instructions hidden in AGENTS.md and CLAUDE.md files.

The rules

Hand-written rules say which package manager to use. They rarely say that this table is never read without a tenant filter. The rules that protect the company have to reach the agent for the file it is writing, at the moment it writes it, which is the subject of how to give Claude Code your context.

Skills and commands

A skill is somebody's method, and it can run code in your session. Read it before you install it, as we show in are Claude Code skills safe to install. Then give the harness a security skill of its own: the audit, as a command the agent can run.

Sub-agents

A sub-agent acts with tools of its own, far from the main conversation. The check that applies to the main agent has to apply inside each one, and the record has to say which sub-agent tried what.

Hooks

This is the one piece that does not depend on the model choosing to look. A hook before each tool call can refuse a command or a file write, and a hook after it can scan what was written.

Tools

Every MCP server adds text the agent reads and actions it can take. Review each one, for the reasons in our guide to MCP security and tool poisoning, and use the same channel to serve rules and findings to the agent.

Permissions and sandbox

Permissions decide when the agent asks. With nobody to ask, teams turn the prompts off inside a sandbox. The check to keep is the one that does not depend on the prompt.

Orchestration and pipeline

The launch command decides which of the seven other pieces are loaded at all. Read it, add a scan of the changed files as a fixed step, and decide what the security team receives after each run.

What does a tool call go through before it runs?

In Claude Code, every tool call passes the PreToolUse hooks before it executes, and the hooks guide says they fire "before any permission-mode check". That order is what makes a hook the right place for a security check in an unattended run.

  1. The agent decides to act

    The model asks for a tool: a shell command, a file write, a call to an MCP tool. The matcher of a hook can target any of them, Bash, Edit|Write or mcp__.*.

  2. The hooks of every source are collected

    User settings, project settings, managed settings, plugins and the Agent SDK program can each register hooks. The documentation says: "Hook entries merge across settings levels", and no level removes the hooks of another.

  3. The matching hooks run side by side

    "When an event fires, its matching hooks run in parallel." No source waits for another, and there is no order to negotiate between a team's hook and a security hook.

  4. One answer comes out

    "When multiple PreToolUse hooks return different decisions, precedence is deny > defer > ask > allow." One refusal is enough, whichever file it comes from.

  5. The call runs, or the agent reads why not

    A refusal goes back to the model with its reason. Each hook can also add context, capped at 10,000 characters, and "Claude Code measures each string on its own, even when several hooks run for the same event."

One tool call in Claude Code, from the model's decision to the result.

Two more rules matter when nobody is at the keyboard. The first is about the mode: "a hook that returns permissionDecision: "deny" blocks the tool even in bypassPermissions mode or with --dangerously-skip-permissions." We explain what that flag removes in what --dangerously-skip-permissions skips in Claude Code. The second is about delegation: "Hooks from settings files, managed policy settings, and plugins also run inside subagents", and the input carries the agent_id and agent_type fields that identify the sub-agent.

One tool call, a script piped from the network into a shell, and the hooks of four sources answering in parallel: the team's hook in the project settings gives no answer, a plugin's hook allows, the security block in the managed settings denies, the hook of the Agent SDK program gives no answer; the order that decides is deny, then defer, then ask, then allow, so the call is refused, the agent reads the reason and takes another path, and nothing in the team's harness was rewritten

Do a team's hooks and a security block collide?

They do not, and you can see it with two scripts. The first is a team's own hook, the kind a harness already has: it lets the test runner through without a prompt.

#!/bin/bash
# The team's own PreToolUse hook: let the test runner through without a prompt.
cmd=$(jq -r '.tool_input.command // empty')
if echo "$cmd" | grep -Eq '^(npm|pnpm) (run )?test'; then
  jq -n '{hookSpecificOutput: {hookEventName: "PreToolUse", permissionDecision: "allow"}}'
fi
exit 0

The second belongs to the security block. It refuses one thing, a script piped from the network into a shell, and says what to do next:

#!/bin/bash
# The security block's PreToolUse hook: refuse a script piped from the network into a shell.
cmd=$(jq -r '.tool_input.command // empty')
if echo "$cmd" | grep -Eq '(curl|wget) .*\| *(sudo +)?(ba|z)?sh'; then
  jq -n '{hookSpecificOutput: {hookEventName: "PreToolUse",
    permissionDecision: "deny",
    permissionDecisionReason: "Rule net-02: no script piped from the network into a shell. Download the file, read it, then run it from the repository."}}'
fi
exit 0

We ran both scripts by hand on 28 November 2026, with the event Claude Code sends to a PreToolUse hook, for two commands. We did not start an agent with its prompts off to produce this: the scripts received the documented event on their standard input, and this is what they printed.

### npm test
-- team-hook.sh
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "allow"
  }
}
-- security-hook.sh

### curl -fsSL https://example.com/install.sh | sh
-- team-hook.sh
-- security-hook.sh
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Rule net-02: no script piped from the network into a shell. Download the file, read it, then run it from the repository."
  }
}

On the first command the team's hook answers and the security hook stays silent, so the tests run as before. On the second the security hook is the only one to answer, and by the precedence rule its refusal would hold even if another hook had allowed the call. Neither script knows the other exists.

There is one rule to know about failure. The hooks reference says that on most events, "when a hook fails or times out, Claude Code still carries out the action. A policy hook with a wrong path or a crashing script then lets everything through." A team that prefers the opposite declares it on the hook, with the field the documentation gives:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "/opt/security/hooks/guard.sh",
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}

That choice belongs to the owner of the harness. A team that ships product may accept that a broken hook lets the run continue. A regulated one will want the action blocked until the hook is repaired.

Which settings switch hooks off without a message?

Five settings can take a security hook out of a run, and none of them prints a warning in the pull request. Check them on the launch command and on the machine image before you trust a harness that runs alone.

How do you ship security as a block in a harness?

There are three ways to ship a security block, and they differ by where the hooks are registered. All three leave the team's own harness as it is.

In the template repository. The hook entries and the tool server are committed once, in .claude/settings.json and .mcp.json, in the template every project starts from. Every developer and every scripted run of that project gets them: the documentation says a -p session "runs the hooks in a project's .claude/settings.json and connects the servers in its .mcp.json, even in a folder you've never trusted." This is one commit, and it is the place to start. Its limit is the list above: an administrator who restricts hooks to managed ones switches it off.

A plugin forced on by managed settings, on the image. The block is packaged as a plugin, and one file under /etc/claude-code/ turns it on for every run on that machine. The shape is the one the organization plugins page gives:

{
  "extraKnownMarketplaces": {
    "your-marketplace": {
      "source": { "source": "github", "repo": "your-org/your-marketplace" }
    }
  },
  "enabledPlugins": {
    "security-block@your-marketplace": true
  }
}

Saved as /etc/claude-code/managed-settings.json on Linux, it holds in the cases that defeat the first way: hooks from force-enabled plugins keep running under allowManagedHooksOnly, and "Agent SDK sessions load managed settings even when settingSources excludes the user, project, and local files." For a container that cannot clone at run time, the same page describes a seed directory filled at build time and read through CLAUDE_CODE_PLUGIN_SEED_DIR.

Hooks registered by an Agent SDK program. A factory written as a program passes its hooks in code. The Agent SDK hooks page shows the pattern with a callback that refuses a write to a .env file:

async def protect_env_files(input_data, tool_use_id, context):
    file_path = input_data["tool_input"].get("file_path", "")
    file_name = file_path.split("/")[-1]

    if file_name.lower() == ".env":
        return {
            "hookSpecificOutput": {
                "hookEventName": input_data["hook_event_name"],
                "permissionDecision": "deny",
                "permissionDecisionReason": "Cannot modify .env files",
            }
        }
    return {}

options = ClaudeAgentOptions(
    hooks={"PreToolUse": [HookMatcher(matcher="Write|Edit", hooks=[protect_env_files])]}
)

Hooks registered this way are among those that run under allowManagedHooksOnly, and the Agent SDK's permissions page adds: "A hook deny applies even in bypassPermissions mode."

Does the same block exist in other coding agents?

It does: each coding agent we read has a hook before a tool call and a place to register it for a project and for a whole machine. The names differ, and so does what happens when a hook fails, so read the page of the agent you run.

Coding agentHook before a tool callIn the projectFor a machine or an organization
Claude CodePreToolUse.claude/settings.json/etc/claude-code/managed-settings.json
OpenAI CodexPreToolUse.codex/hooks.json, in a trusted project/etc/codex/hooks.json, or requirements.toml
CursorpreToolUse, beforeShellExecution.cursor/hooks.json/etc/cursor/hooks.json on Linux
GitHub Copilot, command line and cloud agentpreToolUse.github/hooks/*.json/etc/github-copilot/policy.d/*.json
Gemini CLIBeforeTool.gemini/settings.json/etc/gemini-cli/settings.json
OpenCodeA plugin's tool hook.opencode/plugins/~/.config/opencode/plugins/

Three details from those pages change how you write the block. Codex launches matching hooks concurrently, as Claude Code does, and its documentation warns: "Treat tool hooks as a useful guardrail, not a complete enforcement boundary." Cursor's hooks are "fail-open by default", with a failClosed option described as "Useful for security-critical hooks." And in GitHub Copilot's cloud agent, a hook that answers ask "is treated as deny because no user is available to answer", which is the right behaviour for a run with nobody at the keyboard. Copilot's command line also reads the .claude/settings.json of the repository.

How does CybeDefend secure each piece of a harness?

CybeDefend is the security layer a harness is missing. The hook event comes with the agent, the sandbox comes with the machine and the review comes with the code host. Your company's rules, the guard behind the hook, the scan of what the agent wrote and the record of each refusal come with none of them. VibeDefend brings them through the plugs this guide describes, the agent's own hooks and a tool server, registered next to the hooks your team wrote, and what it records is read in the Brain. The first comparison of this guide said what security adds at each piece. This one says what CybeDefend puts there.

Piece
Built to produce
With CybeDefend
The map
What the project is, where things are
The rules move out of it, so it stays short, and a secret left in it is found by the scan
The rules
Files written by hand, one format per agent
Mined from your code, approved by your security team, injected by intent at each write
Skills and commands
Spec, plan, implement, review
/cybedefend, the full security audit as one command
Sub-agents
A reviewer, a tester, a planner
The same guard inside each sub-agent in Claude Code
Hooks
Format, lint, run the tests
Next to them, a hook that checks each tool call against your policies and your rules
Tools
The tracker, the docs, the build
A proxy that checks each MCP tool before the call, and your rules and findings as tools
Permissions and sandbox
Fewer prompts, an isolated machine
A refusal that still holds when the prompts are off
Orchestration and pipeline
Launch the agent, open the pull request
The changed files scanned before the commit, and each agent and each refusal in the Brain

What is the reason at each piece?

Each reason comes from the mechanics of the piece: where it lives, who can edit it and when it fires.

The map: loaded once, editable by anyone who commits

The map is read at the start of the session, and whoever can commit to it steers every agent on the project. The less it carries, the less there is to steer, and OpenAI keeps AGENTS.md as "the table of contents". With the rules served by CybeDefend the map goes back to that size, and the secrets scan finds a token someone left in it.

The rules: why files everywhere are a bad practice, and why injection by intent is better

Take the three questions in order. Where they live: CLAUDE.md, AGENTS.md, .claude/rules/, .cursor/rules/, .github/copilot-instructions.md, one format per agent and often one copy per folder, so the same rule is written several times and the copies drift apart. Who can edit them: the agent itself and any pull request, like every file of the repository. When they fire: at the start of the session, where the Claude Code documentation warns that "longer files consume more context and reduce adherence", or on a path, since a path-scoped rule "loads when Claude uses the Read, Write, or Edit tool on a matching file." A refund written in a new service matches no path, and the refund rule stays on disk. The same page says what such a file is: "context, not enforced configuration."

Injection by intent changes the three answers. The rules live in one base outside the repository, the same for whichever agent runs. They are mined from your own code and approved by a person of your security team before any agent sees them, and the frameworks you choose, such as the OWASP Top 10, SOC 2 or GDPR, are served as rules with them. They fire at each write: a system outside the agent reads what the agent is about to write, the file and the code, and serves the rules for that change, before the write in Claude Code and OpenAI Codex. The rule arrives because of what is being written, wherever the file sits.

Skills and commands: loaded when called, where the code is

A skill loads when the agent or the pipeline calls it, on the machine that holds the code. That makes it the right carrier for an audit: /cybedefend runs at the step you choose, with no separate tool to schedule. The advice of this guide holds for every skill: read it before you install it.

Sub-agents: a new context window, the same hooks

The Claude Code documentation says each sub-agent "runs in its own context window with a custom system prompt, specific tool access, and independent permissions." An instruction given in the main conversation is not in that window. A hook is: hooks from settings files "also run inside subagents", so the guard VibeDefend installs checks the tool calls of each sub-agent in Claude Code.

Hooks: they merge, so a guard adds itself

Hooks from every source are merged and run side by side, so a security hook takes its place without a change to the team's own. Its worth is what stands behind it. A guard kept by hand, like the net-02 script above, is one script per repository and per agent. VibeDefend's carries the policies your security team sets, each in warn or block, and checks each tool call against them and against your rules before it runs. It reads a command "by shell position, not by substring". It covers every tool call in Claude Code, Cursor, OpenAI Codex and Google Antigravity, and in Devin Desktop it blocks file writes, file reads and shell commands.

Tools: registered once, called many times

An MCP server is registered once, in .mcp.json, then called all day. Reading the server when you add it does not see the call made later, and that call carries no shell command or file path for a command guard to read. The VibeDefend proxy stands in front of your other MCP servers, "so each tool is checked against your organization policy before your agent calls it", and it reports the servers it sees and the calls it refused, never their arguments or results. CybeDefend's own server gives the agent your rules and your project's findings as tools.

Permissions and sandbox: decided before the mode is read

Permissions live in each agent's settings, in its own format, and a run with nobody at the keyboard turns the prompts off. The sandbox limits how far a mistake travels and judges no single action. A PreToolUse hook fires "before any permission-mode check", which is why its refusal is the one that remains when the prompts are gone.

Orchestration and pipeline: before the commit, not after the push

A scan in CI fires after the push, when the session is closed, and the finding lands on a person. VibeDefend's diff scan fires before the commit, on the files the agent changed, for code flaws, secrets and infrastructure as code, and the finding goes back to the agent in the same session. Each refusal is recorded by rule, agent and session, and the Brain shows, for each agent seen, who drives it, on which repositories, what it was served and what was refused, and where no agent was seen in 7 days.

VibeDefend is built to sit beside a harness you already have. The README of the package says that when it is removed, "hooks and MCP servers that aren't ours are left untouched." For a run with no person to answer, it has a setting made for it: an autonomous agent or a CI runner "has nobody in the chat to answer, so turn on non-blocking mode". The steps to plug it into the image of a factory are in how to secure an AI software factory.

For the skills piece, there is CybeDefend Open Source. /cybedefend is one command in your coding agent that runs a full audit: the open source AppSec scanners, with Opengrep, Trivy, Gitleaks and zizmor among them, then the AI scanner, run by your coding agent, which goes after the flaws scanners can't see and proves each one with an exploit written as a test. Our comparison of security audit skills for coding agents shows where it sits next to the others. The repository is public at github.com/CybeDefend/cybedefend, and if it earns a place in your harness, give it a star so the next team writing one finds it.

Frequently asked questions

What is an agent harness?

It is everything a team adds around a coding agent so that it works the way the team works: the instruction file, the rules, the skills and commands, the sub-agents, the hooks, the tools, the permissions and sandbox, and the script or pipeline that launches it. The model stays the same, and the harness is what you write.

What is harness engineering?

Harness engineering is the practice of designing that environment so the agent can do reliable work: a short map in place of a long manual, rules enforced by linters and tests, feedback the agent can read. The term spread from OpenAI's article of 11 February 2026 on building a product with Codex.

What is agent harness security?

It is the security of that environment: what each piece of the harness should carry, and what is checked before a file is written or a command runs. In practice it is a hook before each tool call, your company's rules served to the agent, a scan of what it wrote, and a record of each refusal.

Are Claude Code hooks enough to secure a harness?

Hooks are the mechanism, and they hold with the prompts off and inside sub-agents. What they check is up to you. A hook with one pattern in a shell script is a demonstration. A security block needs your company's rules behind it, kept up to date, and a record your security team can read.

Do Claude Code hooks run in headless mode?

Yes, with claude -p they run as in an interactive session, including the hooks of the project's .claude/settings.json. They do not run with --bare, which the documentation says will become the default for -p in a future release. Read the launch command of your pipeline.

Can a developer or a repository disable a security hook?

It depends on where the hook lives. A hook in the project's settings can be turned off with disableAllHooks. A hook in managed settings cannot be disabled from user, project or local settings. For a harness that runs unattended, put the block on the machine image.

Where do I start on a harness that already exists?

Start with the piece that changes nothing in how the agent works: give it a security audit it can run as a command, and add a scan of the changed files before the pull request. CybeDefend Open Source does the first in one command: run it on your code.