1h 1m read

Monitoring Sees the Escape. The API Can't Stop It.

Detection is not control: why agent escapes are only visible after the fact, and how to move the stop to the API boundary with identity, typed requests, deterministic policy, fail-closed decisions, and durable denial records.

Monitoring Sees the Escape. The API Can't Stop It.

Monitoring is a detection instrument, and detection is structurally too late to be control. Every escape your dashboards surface has already happened: the call completed, the record was written, and the failure budget you are tracking was spent rather than protected. That is not a monitoring defect. It is what monitoring is for.

The gap matters most for teams that own agent infrastructure, because an agent's failure mode is not a wrong answer in a chat window — it is an authorized-looking API call that reached a resource it should not have touched. This article separates detection from enforcement, offers a taxonomy of escape shapes that monitoring can only classify after the fact, argues that the tool or API boundary is the one place a stop can be deterministic, and sets out five requirements for enforcement there. It then turns those requirements into acceptance tests that prove a stop occurred, and closes by giving observability back the jobs it is genuinely good at: audit and drift detection.

Detection and enforcement are different questions, and only one of them is a control

Detection answers "what happened." Enforcement answers "may this happen." The two questions are answered by different components, at different moments, with different failure modes, and conflating them is the most common reason an agent security program looks complete on a slide and behaves incompletely in production.

A monitoring system observes a request after it has been formed. In most agent architectures it observes the request after it has been executed, or while it is in flight — the span is opened when the tool call starts, the log line is written when the call returns. Whatever the pipeline does with that record, its output is a description of an event, not a gate in front of one. The gate has to exist somewhere else, and it has to be consulted before the effect.

The failure-budget framing makes the distinction concrete. A budget is only meaningful if something can refuse to spend it. If you define a per-session cost ceiling, a maximum chain depth, or a cap on records read, and the only component that knows about the ceiling is a dashboard, then the ceiling is a reporting threshold, not a limit. Monitoring can tell you the budget was exceeded. It cannot decline the transaction.

Teams slip past this because the alert often arrives close in time to the event. A well-tuned pipeline can page someone within seconds of an anomalous tool call, and seconds feel like control. They are not. "Close in time" and "before the event" are different properties, and only the second one changes whether the side effect occurred. A fast alert improves your response time; it does not improve your outcome for the request that already went through. The rest of this article is about where the outcome can still be changed.

Three shapes of escape that monitoring can only capture after the fact

The taxonomy below is a model for reasoning about coverage, not a measured finding from a study. Treat it as a lens: it helps you decide what your enforcement layer must be able to see, and it deliberately does not claim to be exhaustive.

Scope escape. The agent acts on an object, tenant, or resource outside its intended boundary. It reads the wrong customer's table, writes to a bucket in another environment, or calls an internal service that was never in its remit. The action is fully formed and perfectly legible in the log — the log just happens to be written after the read or the write landed.

Intent escape. The action sits inside the permitted surface but serves a purpose the operator never authorized. Every individual permission is legitimate: the agent may read the repository, may call the HTTP tool, may summarize documents. What was never authorized is the combination — reading a configuration file and then posting its contents to an external endpoint. Anthropic's containment write-up describes exactly this shape in its egress incidents, where data left through a permitted path and, in the authors' words, "there was nothing anomalous for [the model layer] to catch." The same write-up notes the harder version of the problem: once a poisoned tool return has steered an agent into exfiltration, "the log just shows a successful, authorized API call. There's no after-the-fact signal to find."

Volume escape. Each action is individually permissible, but the aggregate — request rate, chain depth, cumulative cost, total data moved — crosses a limit that no single request violates. This is the hardest shape for monitoring, because no individual event looks anomalous. A hundred reads of one row each are a hundred unremarkable log lines. The signal only exists in the aggregate, and by the time the aggregate is visible, the aggregate has already happened. The OWASP AI Agent Security Cheat Sheet names the cost variant directly as denial of wallet: excessive API or compute spend driven by unbounded agent loops.

All three shapes share the same retrospective structure. The record is written when the call completes, so the taxonomy describes what a post-hoc review can classify, not what a gate can prevent. Its value is in design: for each shape, ask which component could have refused the action, and whether that component held enough context to recognize the shape at the moment of decision. If the answer for any shape is "the dashboard," that shape is currently uncovered.

The API boundary is the only place a stop can be deterministic

The tool or API call is the natural enforcement point because it is the last place where the system still holds a complete, structured description of the intended action before that action takes effect. Upstream of the call you have a model's reasoning, which is probabilistic and not a control surface. Downstream of the call you have an effect, which is what you were trying to prevent. At the call itself you have a named tool, a set of parameters, a caller identity, and a moment in time — enough to decide.

The architecture for this is well established, just not yet standard for agents. OWASP's Authorization Patterns guidance separates the Policy Enforcement Point (PEP), which protects an operation, from the Policy Decision Point (PDP), which evaluates the applicable policy. It advises keeping enforcement close to the protected resource so the PEP can check the requested action, object, and tenant, and it is explicit that separating evaluation from enforcement does not transfer the PEP's responsibility to enforce the result. Envoy's external authorization filter is the canonical illustration of delegation to a PDP, and the same page documents a subtlety that matters for agents: routing changes after authorization can invalidate an earlier check.

Two cautions follow. First, a gateway's coverage is a deployment property, not an automatic one. OWASP's guidance is blunt that complete traffic coverage must be treated as a deployment requirement — permitted callers authenticated, direct access to services restricted, internal calls and alternate endpoints covered. A gateway that fronts the public API but not the service-to-service path has a hole shaped exactly like the calls an agent is most likely to make. Second, and more important for this discussion, typical API gateways are not yet policy decision points for agents. They authenticate callers and apply coarse rules — path prefixes, methods, rate limits, sometimes scopes. What they generally lack is the agent-specific context a real decision needs: which agent is acting, on whose behalf, for what purpose, and under which delegation chain. Without that, the gateway can tell you a valid credential made the call. It cannot tell you whether this agent should have made this call for this user.

That is a gap in current typical deployments, not a law of nature. A gateway can be extended, and the external-authorization pattern is precisely the extension path: keep the PEP where the call happens, and give it a PDP that understands agents. The point is that the decision has to be designed, not assumed from the fact that a gateway is already in the path.

Five requirements for enforcement that actually stops something

The following is a methodology, not a survey of products. Each requirement is paired with the reason it is necessary and the escape shape it closes.

1. Identity per action. Every call must carry a verifiable workload identity for the agent and the delegated user context for whom it acts. Without this, policy has no subject to evaluate and the PDP can only fall back to the caller's network position. SPIFFE provides the workload identity primitive — a URI-shaped identity bound to a key and delivered in a short-lived verifiable document. RFC 8693 provides the delegation primitive: OAuth 2.0 token exchange, which explicitly covers tokens "employing impersonation and delegation" and frames the exchanged actor as an agent for the subject. One caution from the SPIFFE specification is worth carrying into design: assertions embedded in a credential remain valid for that credential's lifetime, so if an assertion's volatility is unclear, exclude it and carry it in a separate, shorter-lived artifact. A permission that can be revoked in seconds does not belong inside a credential that lives for hours. This requirement closes intent escape at the root, because "on whose behalf and for what purpose" becomes an input to the decision rather than an inference from the audit trail.

2. Typed requests. The action must be expressed as a structured, schema-validated object so policy can evaluate fields rather than parse prose. The OWASP AI Agent Security Cheat Sheet shows the shape in its tool-call validation example: a typed model with an allowlist for tool names and parameter checks that reject sensitive material before the call proceeds. This is what makes policy writable at all. A policy that has to interpret free text is a classifier, and classifiers are probabilistic. A policy that reads tool_name, target_tenant, and record_count is deterministic. This requirement closes scope escape, because the object and tenant become checkable fields.

3. Deterministic policy evaluation. A policy engine evaluates the structured input and returns a decision, decoupled from enforcement. Open Policy Agent is the reference example: it is a general-purpose policy engine that "decouples policy decision-making from policy enforcement," queried with structured data as input and answering in a declarative language. The decoupling is the point — policy can be reviewed, versioned, and tested independently of the service that enforces it, and multiple teams can contribute independent policy packages combined into one decision. This requirement closes intent escape at the level of combinations: rules can express "this tool, for this purpose, with this data class" rather than one permission at a time.

4. Pre-execution decision. The decision must be obtained and enforced before the call reaches the resource, and the PEP must fail closed when the PDP errors or times out. OWASP's guidance is direct: configure PDP errors and timeouts to deny protected operations, and deny the operation if no valid decision is available. Envoy's failure-mode setting makes the choice explicit in configuration — allowing requests when authorization fails bypasses the control. This is the requirement that converts the previous three from analysis into enforcement. It closes all three shapes, but only for the calls it actually covers, which is why coverage is a deployment property.

5. Durable denial record. Every denial must be written with when, where, who, what, and why, and protected against tampering. The OWASP Logging Cheat Sheet sets the attribute baseline — the application logs must record "when, where, who and what" for each event, plus the reason the status occurred — and adds the controls that make the record evidence: tamper detection so you know if a record was modified or deleted, and copying to read-only media as soon as possible. It also warns that data from a different trust zone may be missing, modified, forged, or replayed and must be treated as untrusted. This requirement closes volume escape in the only way it can be closed: the aggregate becomes visible because every refusal is recorded with enough context to count. It also makes the other four auditable, because a denial record is the proof that the gate was exercised.

Writing acceptance tests that prove a stop occurred

A test that proves detection asserts that the event appears in telemetry. A test that proves enforcement asserts that the action did not occur and that a denial was recorded. These are different tests with different pass conditions, and a suite that only contains the first will pass against an architecture with no gate at all.

Start with one positive test per tool: a permitted action, with valid identity and delegation, succeeds, and the decision is recorded as permitted alongside the enforcement. This is the control case. Without it, a fail-closed configuration that denies everything would look like a perfect score.

The negative tests are where the enforcement claim is actually tested. Each of the following must be denied, and each denial must produce a record:

  • Unknown tool. A call to a tool outside the allowlist is refused even when the request is otherwise well-formed.

  • Missing identity. A call with no verifiable agent identity, or with identity but no delegated user context, is refused.

  • Expired or replayed approval. An approval past its validity window is refused; an approval already consumed is refused on reuse.

  • PDP unavailable. With the decision point stopped or unreachable, the call is denied rather than allowed.

  • Policy evaluation error. A malformed input or a policy that raises an error results in denial, not a default permit.

  • Parameters changed after approval. An approval bound to one target and parameter set does not authorize a different one.

The approval cases deserve their own emphasis, because they are where implementations most often look correct and are not. The OWASP AI Agent Security Cheat Sheet is precise: a user_confirmed flag is insufficient, because the component must verify that the approval belongs to the current actor and the exact tool call, remains valid, and has not already been consumed — and it must check and consume the approval in one atomic step immediately before execution so concurrent or repeated requests cannot reuse it. Changes to the target or parameters require a new approval. A test that fires the same approval twice concurrently and observes two executions has found a real defect, not a flaky test.

The pass condition is the part teams get wrong. A negative test passes only when the side effect is absent. Assert on the resource state — the row unchanged, the object not written, the external endpoint never contacted — not merely on the response code. A denial returned to the caller after the write already landed is a detection event wearing an enforcement costume. Pair every negative test with a check that a denial record exists for the blocked attempt, with the attributes from requirement five, so the test proves both halves: nothing happened, and the refusal is on the record.

Where observability still earns its keep

None of the above makes monitoring optional. It makes monitoring's job different from the one it is often assigned.

Observability's first real job is audit: reconstructing what happened, in order, with enough context to answer who acted, on whose behalf, on what object, and with what decision. The denial records from requirement five are the spine of that reconstruction, and the permitted-action records are the rest of it. This is the work the OWASP Logging Cheat Sheet is written for — a chronological record that permits reconstruction, review, and examination of the original sequence of attributable transactions.

Its second job is drift detection: noticing when the distribution of permitted actions shifts in ways policy has not caught up with. A new tool entering the mix, a change in which tenants an agent touches, a slow rise in chain depth — these are aggregate signals, and aggregates are what telemetry is good at. Drift detection is not enforcement, but it is how you learn that the policy needs a new rule before the next incident writes it for you.

The scope claim here is narrow and worth stating plainly. OpenTelemetry describes itself as an observability framework and toolkit for generating, exporting, and collecting telemetry, and states that it is not an observability backend itself — the backend and frontend are intentionally left to other tools. Nothing in that description is an enforcement mechanism. Instrumentation tells you what your system did; it does not decide what your system may do.

Anthropic's containment account supplies a useful illustration of the trade. Isolation reduces visibility, and the authors say so directly: their mitigation for teams whose compliance posture depends on endpoint visibility is pull-based OTLP export that lets administrators retrieve event logs after the fact, which they explicitly note "is not the same as live monitoring." That is the right framing. The export is an audit channel. It is not a gate, and treating it as one would recreate the original problem in a new place.

The division of labor is clean. Enforcement decides. Observability explains, and watches for drift. Neither substitutes for the other, and a design review should be able to point at the component that does each.

An acceptance checklist for the design review

Each item is phrased so a reviewer can answer yes or no in the meeting. A "no" is a finding, not a discussion point.

  • Does every tool call pass through a policy enforcement point before execution, including internal and service-to-service calls?

  • Does each request carry a verifiable agent identity and the delegated user context, with volatile assertions kept out of long-lived credentials?

  • Are requests typed and schema-validated, so policy evaluates fields rather than prose?

  • Is policy evaluated deterministically by a decision point, with policy and input versions recorded alongside the decision?

  • Do PDP errors and timeouts deny by default, and is that failure mode set explicitly in configuration rather than inherited?

  • Does every denial produce a durable record with when, where, who, what, and why, protected against tampering?

  • Are approvals bound to actor, action, and parameters, and checked and consumed atomically before execution?

  • Do negative tests assert the absence of the side effect on the resource, not just the response code?

  • Is telemetry wired for audit and drift detection — and is it explicitly not counted as a control in the risk register?

FAQ

Isn't a fast alert good enough? No. A fast alert changes your response time; it does not change whether the action happened. The request that triggered the page has already executed. Alerting is worth having, and it belongs in the audit and drift-detection column, not the control column.

Our gateway already does authorization. Coarse caller authentication is not agent-aware policy decision. A gateway that validates a credential and applies path and method rules can tell you a permitted caller made the call. It generally cannot tell you whether this agent, on this user's behalf, for this purpose, should have made it. That context has to be supplied to a decision point, and the enforcement point has to consult it before execution.

Won't fail-closed break availability? It can, and that is the intended trade. The point is that it must be an explicit, reviewed choice rather than a default that emerges from configuration. OWASP's guidance is to deny protected operations when no valid decision is available; Envoy's failure-mode setting exists precisely to make the alternative visible when someone chooses it. If your availability requirement genuinely cannot tolerate a PDP outage, that is an argument for making the PDP highly available, not for silently permitting on failure.

Can't the model just be told not to escape? Prompt-level constraints are probabilistic and bypassable. The AWS Agentic AI Lens guidance lists defining operational boundaries in natural-language system prompts alone, relying on the model's instruction-following as the sole constraint, as an anti-pattern, and recommends layered controls that are deterministic where possible. Instructions are one layer. They are not the boundary.

Where does the agent's own reasoning fit? It proposes; the boundary disposes. The agent's plan, its tool selection, and its parameter choices are inputs to the decision, and the decision point evaluates them against policy. Reasoning is what makes the agent useful. It is not what makes the system safe.

Conclusion: move the stop before the log line

Monitoring is necessary, and it is not a control. The only place a stop can be deterministic is the API boundary, before execution, where the system still holds a structured description of the intended action and a component exists that can refuse it. The shift this article argues for is from "we can see it" to "we can refuse it," with observability repositioned where it belongs: audit and drift detection, explaining what enforcement decided and watching for the cases policy has not yet learned.

What changes when enforcement is real is worth stating plainly. Failure budgets become enforceable rather than aspirational, because something can decline to spend them. Denials become evidence, because each one is a durable record that the gate was exercised. And the escape taxonomy stops being a postmortem template and becomes a coverage map: for each shape, you can point at the requirement that closes it and the test that proves the closure.

A practical next step: take the acceptance checklist above to one agent workflow this quarter. Pick the workflow with the widest tool access, walk the nine questions, and record the "no" answers. That list is your enforcement backlog, and it is more useful than any dashboard.