Guide
What is runtime security for AI coding agents?
Updated
Short answer
Runtime security for AI coding agents checks each action an agent takes (a command, file edit, network call or push) just before it executes. It then allows the action, rewrites it to a safe version or blocks it. That makes it different from build-time scanning, which reads code after it's written, and from prompt filtering, which reads text. To work, the check should run outside the agent at its pre-execution hook, decide locally and fast enough that nobody turns it off, and fail closed.
What it checks, and when#
An agent doesn't just write code. It runs shell commands, edits files, calls tools and pushes to remotes, using the developer's credentials.
Runtime security works at the one point where all of that is still a proposal: after the agent decides to act and before the action happens. Scanners look at what already got written. Prompt filters look at what went into the model. Runtime security looks at the action that's about to touch your laptop, repo or cloud account.
How it differs from the other layers#
Each of these is useful. None of them answers "should this specific action run right now?"
- Build-time scanning (SAST, SCA, DAST): finds flaws in the code an agent generated. It can't see a
curlthat already sent a token out, or a force-push that already landed. - Sandboxes: limit what a shell command can reach. Claude Code's docs say the sandbox covers shell commands only, and that file tools, MCP servers and hooks run outside it.
- Network firewalls and egress allowlists: limit where traffic can go. They can't tell whether a request to an allowed host carries a secret or a changelog.
- Prompt filtering: screens input and output text. A poisoned README or issue doesn't have to look like an attack to cause one. The harm shows up as an action.
- Permission rules: match tool calls by pattern and ask a human. They handle the obvious cases, but they match text, and the same delete can be written many ways.
Anthropic's docs say sandboxing, permission rules and permission modes are complementary layers. A runtime check adds one more layer. It doesn't replace scoped credentials or egress policy.
Why a human clicking approve isn't the check#
Approval prompts are the default runtime control, and people stop reading them. Anthropic's own research found that users accept 93% of manual prompts anyway.
In Harden's internal use, agent sessions average 145 actions, and long ones go past 1,000. Nobody reads 1,000 prompts. A control that costs a human something on every action gets switched off or clicked through.
Why it has to sit outside the agent#
If the check lives in the agent's prompt, instructions or context, the agent is grading its own homework. Injected content can override instructions. A long session can compact its context and drop them.
The right place for the check is the agent's pre-execution hook. Claude Code, for example, runs PreToolUse before a tool call executes, and that hook can block it. The harness calls the hook, but something else makes the decision, using its own policy.
There's a catch in the same docs. If a hook fails to start, prints invalid JSON or exits with an unexpected code, Claude Code treats it as a non-blocking error and the action goes ahead. A hook meant to enforce policy has to fail closed: if the check can't run, the action shouldn't either. More on this in what Claude Code hooks enforce.
Why checking the action beats matching strings#
String matching asks "does this text look dangerous?" Quoting, aliases, harmless-looking flags, encodings and other languages all change the text without changing what the command does.
Checking the action means parsing the command and following where the data goes. A secret that reaches a network call is a dangerous flow however the command is spelled.
The harder cases need intent: the same command can have two intents. Deleting a test file is a refactor in one session and a way to hide a failure in another.
Editing CI config, adding a dependency or widening an IAM policy are ordinary until the session's goal says otherwise. Only a check that knows what the session was asked to do can tell the two apart.
What speed and locality require#
The check runs on every action, so its latency adds up over a session. If each check costs a noticeable pause or a network round trip, developers will disable it.
A check that decides on the laptop has no cloud dependency that can stall a session. It also doesn't send source code or secrets anywhere to get a verdict.
Where Harden fits#
Harden Agentic Integrity Foundation (AIF) is a runtime product built this way. It runs on the developer laptop, outside the agent, at the agent's pre-execution hook. Every command, file edit and push is checked against the session's intent before it runs.
Deterministic rules decide on their own when the action itself is the evidence. A local model reviews the action in the context of the session and can only make a verdict stricter, never weaker. Verdicts take about 28 ms (P99 about 70 ms). Nothing leaves the machine, and if the check can't run, the action doesn't run.
AIF applies one policy across agents, ships through the MDM you already run, and starts watch-only, so you can see what agents do before you enforce anything. It's a layer, not a perimeter. It doesn't replace least privilege, scoped credentials or egress policy, and exfiltration spread across several separate calls is still the hard case.
For the mechanism in detail, see what a pre-execution check should do. For the layers built into Claude Code, see permission rules vs hooks vs sandboxing.
A decision rule#
When you evaluate any runtime control for coding agents, ask these questions:
- Does it run before the action executes, not after?
- Does it sit outside the agent's own context and privileges?
- Does it fail closed when it can't run?
- Does it judge the action in the context of the session, not just the text?
- Does it decide locally, fast enough that nobody turns it off?
FAQ
Related questions
Is runtime security the same as a sandbox?
No. A sandbox limits what a shell command can reach once it runs. Runtime security judges each action before it runs. Claude Code's sandbox covers shell commands only, so file tools, MCP servers and hooks fall outside it. Use both.
Does runtime security replace build-time scanning?
No. Scanning finds flaws in the code the agent wrote. Runtime checks stop risky actions, such as leaking a secret or force-pushing, before they happen. They cover different moments, so you need both.
Why can't the coding agent check its own actions?
Its instructions live in its context. Injected content can override them, and a long session can compact them away. A check that runs outside the agent, at the pre-execution hook, doesn't depend on the agent behaving.
How much latency is acceptable for a runtime check?
Low enough that developers don't disable it. Harden's verdicts take about 28 ms, with a P99 of about 70 ms, because decisions are made locally on the laptop.
Can I try it without blocking anything?
Yes. Harden starts watch-only. It logs what agents do so a security team can review it before turning on enforcement.