This lesson treats an agent acting outside its brief as a security incident with a specific shape: fast, carried out under delegated credentials, and reconstructable only from telemetry. It covers the threat model, detection signals, containment mechanics (including why killing the process and revoking the token are different operations), evidence capture, blast-radius scoping, and how to turn each incident into a regression test. It maps the work onto NIST SP 800-61r3 so it slots into an existing security programme.
Threat model: how agents leave their brief
Define the brief as the task plus its intended authority envelope: principals the agent acts for, resources it may read, actions it may take, destinations it may send data to, and the time window. An incident is any tool call or side effect outside that envelope. Five mechanisms account for most cases.
| Class | Mechanism | Typical signature |
|---|---|---|
| Capability failure | Model misreads the task, picks the wrong record, hallucinates an argument | Plausible but wrong tool arguments; no external trigger in context |
| Indirect prompt injection | Attacker-controlled text in retrieved content is treated as instructions [1] | Behaviour change immediately after a tool result containing imperative text |
| Excessive agency | Agent holds functions, permissions or autonomy beyond the task, so any error is amplified [2] | Calls to tools the task never needed; writes where reads would do |
| Tool or server compromise | Malicious or altered tool descriptions, or a compromised MCP server [3][4] | Tool definitions changed since approval; instructions inside descriptions |
| Confused deputy | A component with legitimate authority is induced to use it for another party [5][6] | Actions attributed to the user or service account that the user never requested |
These are not exclusive. Greshake et al. showed that processing retrieved prompts can “act as arbitrary code execution” and control “how and if other APIs are called” in LLM-integrated applications [1]. OWASP’s LLM06 entry is explicit that excessive agency is the vulnerability “regardless of what is causing the LLM to malfunction”, whether hallucination, direct or indirect injection, or a compromised peer agent [2]. In other words, injection is the trigger and excessive agency is the amplifier; incident response has to deal with both.
The base rate matters for planning. ToolEmu, an LM-emulated sandbox with 36 high-stakes tools and 144 test cases, found that even the safest agent evaluated exhibited failures with potentially severe outcomes 23.9% of the time according to its automatic evaluator, and human review judged 68.8% of ToolEmu-identified failures to be valid real-world failures [7]. AgentDojo, with 97 tasks and 629 security test cases, found that existing prompt injection attacks “break some security properties but not all” and that models fail many tasks even without attack [8]. Neither number transfers directly to production, but both justify treating out-of-brief behaviour as a recurring operational event with a runbook, not an exception.
Mapping onto NIST SP 800-61r3
The 2025 revision of SP 800-61 replaces the old four-phase life cycle with the six NIST CSF 2.0 Functions. Govern, Identify and Protect are preparation; Detect, Respond and Recover are the incident itself; and the Improvement category (ID.IM) receives lessons from all of them [9]. NIST notes that lessons “should often be shared as soon as they are identified, not delayed until after recovery concludes” [9].
| CSF 2.0 Function | Agent-specific work |
|---|---|
| Govern | Name an accountable owner per agent; define what counts as an agent incident; set notification thresholds |
| Identify | Maintain an inventory of agents, their tools, credentials, data stores and egress paths |
| Protect | Least-privilege grants, human approval on consequential tools, egress allowlists, short-lived credentials |
| Detect | Tool-call telemetry, policy-denial alerts, anomaly rules on destinations and volume |
| Respond | Kill switch, credential revocation, evidence capture, scoping, notification |
| Recover | Undo side effects, restore data, re-enable with narrowed grants |
| Identify: Improvement | Post-incident review, new evaluation cases, permission changes |
NIST SP 800-53’s IR-4 control expresses the same loop: an incident handling capability covering “preparation, detection and analysis, containment, eradication, and recovery”, with lessons incorporated into procedures, training and testing [10].
Detection: what to watch
You cannot detect what you do not record. At minimum, every tool call should produce a structured event with the fields NIST SP 800-53 AU-3 asks of any audit record: event type, time, location, source, outcome, and the identities involved [10]. For agents, extend that with the agent identity, the human principal, the grant or token identifier (never the token value), the tool name, a digest of the arguments, and the result status. Lesson 10 covers the schema in detail.
Useful detection rules, roughly in order of signal-to-noise:
- Policy denials. A burst of denied tool calls is often the first sign that an agent has been redirected. Denials are cheap to alert on because they should be rare.
- New destinations. First-seen email recipients, domains, webhook URLs or repositories, especially immediately after the agent processed external content.
- Tool-set drift. Calls to tools the task template never uses, or any change in a server’s tool definitions since they were approved.
- Volume and tempo. Rate of sends, deletes, downloads or record reads far above the agent’s baseline.
- Sequence patterns. A read of sensitive data followed by an outbound communication in the same run. This is the observable form of what Simon Willison calls the “lethal trifecta”: private data, untrusted content and external communication in one context [11].
OpenTelemetry’s generative AI semantic conventions define spans such
as execute_tool with attributes including
gen_ai.tool.name and gen_ai.tool.call.id, and
mark tool arguments and results as opt-in because they may contain
sensitive data [12]. The conventions
are still in Development status, so pin the version you emit and expect
attribute names to change.
Containment: process, credentials and egress are separate levers
The most common containment mistake is to stop the agent process and consider the incident contained. There are three independent levers, and each closes a different path.
| Lever | What it stops | What it does not stop |
|---|---|---|
| Kill or pause the agent loop | New model decisions and new tool calls from that runtime | Tokens already issued; scheduled jobs; other runtimes holding the same credential; work already queued downstream |
| Revoke credentials and grants | Any further use of the credential, from anywhere | In-flight requests already accepted; data already exfiltrated |
| Cut egress | Outbound transfer to new destinations | Damage inside systems the agent can still reach |
Do all three, in the order that fits the incident. If data is actively leaving, cut egress first. Otherwise, pause the loop, then revoke.
Revocation in practice
OAuth 2.0 defines a revocation endpoint (RFC 7009) that lets a client tell the authorisation server a token is no longer needed, and revoking a refresh token can also invalidate access tokens derived from the same grant, depending on server policy [13]. The catch is self-contained access tokens such as JWTs: a resource server that validates them locally will keep accepting them until expiry unless it checks status. Token introspection (RFC 7662) lets a resource server ask the authorisation server whether a token is still active [14]. Your effective revocation latency is therefore the shorter of the access token lifetime and the introspection or cache interval. Know that number before an incident; it is the window in which a stolen token still works.
The OAuth 2.0 Security Best Current Practice (RFC 9700) recommends restricting token privileges to the minimum required, audience-restricting access tokens to a specific resource server, and sender-constraining or rotating refresh tokens for public clients [15]. Each of these shrinks what a leaked credential can do during the revocation window.
If the agent could read a static secret (an API key, a database URL, a password), revoking the agent’s grant is not enough. Rotate the secret itself, because you cannot prove it was not copied into a log, a model provider’s context or an attacker’s server.
A kill switch that actually works
Design the kill switch as a policy decision, not a process signal. A pattern that holds up:
# Illustrative runbook entry, not tied to any product
agent: bookings-triage
owner: mia@example.org
kill_switch:
pause: "Set agent status to 'suspended' in the policy store; the gateway denies all tool calls for this agent ID"
revoke:
- "Revoke OAuth grant for client_id bookings-triage at the authorisation server (RFC 7009)"
- "Rotate shared mailbox app password"
egress: "Remove agent's outbound mail permission; block non-allowlisted SMTP recipients"
verify:
- "Attempt a harmless tool call as the agent; expect a policy denial event"
- "Introspect the revoked token; expect active=false"
max_revocation_latency: "5 minutes (access token TTL)"The important property is that the denial is enforced outside the model, at a gateway or resource server the agent cannot talk its way past. OWASP calls this complete mediation: authorisation implemented in downstream systems “rather than relying on an LLM to decide if an action is allowed or not” [2].
Evidence: capture before you clean
Agent incidents are reconstructed from telemetry. Capture these before anyone edits configuration or deletes content:
- The full run transcript: system prompt version, user messages, model outputs, and every tool call with arguments and results.
- The triggering content: the email, web page, document or issue the agent read, in original form (raw MIME, HTML source), plus a hash.
- Tool definitions as they were: names, descriptions and schemas served at the time. Tool poisoning attacks hide instructions in descriptions the user never sees [3], so a later, cleaned-up definition is not evidence.
- Model and runtime identifiers: model name and version, agent framework version, MCP server versions.
- Credential identifiers: grant IDs, token IDs or
jtivalues, client IDs and scopes. Never copy token values into the incident record. - Downstream logs: mail server, identity provider, cloud audit logs and repository audit logs for the window.
ASD’s ACSC and its co-authors recommend centralised log collection, timestamps in UTC using ISO 8601 with millisecond precision where possible, cryptographic integrity protection for logs in transit and at rest, and retention long enough for investigations that may start months later [16]. Copy evidence to write-once or access-restricted storage and record a hash of each artefact at capture time.
Scoping the blast radius
Start from the agent’s identity and the incident window, and enumerate every side effect. If your audit events are structured, this is a query, not an archaeology project:
-- Illustrative: every action by the agent in the window, external destinations first
SELECT ts_utc, tool_name, action, target, destination, outcome, grant_id
FROM agent_audit
WHERE agent_id = 'bookings-triage'
AND ts_utc BETWEEN '2026-11-10T01:30:00Z' AND '2026-11-10T03:00:00Z'
ORDER BY (destination IS NOT NULL AND destination NOT LIKE '%@harbourstreet.example') DESC,
ts_utc;Then widen the scope deliberately. Which other agents or users share the credential? Which other runs processed the same malicious content (the same email may be in several inboxes)? Did the agent write anything that another agent will later read, creating a second-order injection? Greshake et al. describe “worming”, where injected instructions propagate through content an LLM writes and another reads [1].
Eradication and recovery
Eradication removes the cause, not just the artefacts:
- Quarantine the injected content so no other agent run can retrieve it.
- If a tool server was involved, pin or remove it and diff its current tool definitions against the approved version. The MCP project’s security guidance recommends checking provenance before installing local servers and treating tool definitions as untrusted input [17].
- Remove any permission the agent held that the task did not need. This is usually the real root cause.
- Split capabilities that combine into the trifecta: an agent that reads untrusted email should not also be able to send to arbitrary recipients in the same context without approval [11].
Recovery is undoing side effects (recalling or following up on messages, reverting commits, restoring files, cancelling transactions) and re-enabling the agent with narrower grants and closer monitoring for a defined period.
Notification obligations in Australia
If personal information was accessed or disclosed without authorisation, assess whether it is an eligible data breach under the Notifiable Data Breaches scheme: unauthorised access, disclosure or loss that is likely to result in serious harm and that remedial action has not prevented. The OAIC states that an entity must take all reasonable steps to complete its assessment within 30 calendar days of becoming aware of grounds to suspect an eligible breach, and that the Commissioner expects 30 days to be treated as a maximum [18]. The scheme applies to APP entities, which generally excludes small businesses under the AU$3 million turnover threshold, but some small businesses are covered, including health service providers [18]. Record your assessment reasoning either way, and get legal advice; this lesson is not it.
Worked example: a coding agent and a poisoned issue
Northline Digital is a six-person agency. Sam runs a coding agent that triages GitHub issues on client repositories and opens pull requests. It authenticates with a personal access token that has write access to every repository in the organisation, because that was quicker to set up.
A new issue on a public client repository contains a paragraph addressed to “the AI assistant”, asking it to add a “diagnostic” step to the CI workflow that posts environment variables to an external URL. The agent opens a pull request doing exactly that on the public repository, and because Sam’s automation auto-merges dependency-labelled PRs, it merges.
Detect. A rule fires on a first-seen outbound domain in a CI workflow change made by the agent’s identity.
Respond. Sam pauses the agent in its policy store (all tool calls denied). He revokes the token at GitHub and rotates every secret available to that repository’s CI, because the workflow may already have run. He reverts the commit and disables the workflow.
Preserve. He saves the issue body as raw markdown, the agent transcript, the PR diff, the CI run logs and the organisation audit log for the window, hashing each file.
Scope. The audit query shows the agent touched one repository in this run, but the same token could write to 23 others. Log review shows no other writes. CI logs show one run of the malicious step; the client’s deployment key was exposed.
Recover and improve. The client is notified and
rotates the key. Sam replaces the token with a fine-grained token scoped
to one repository with an expiry, a capability GitHub recommends over
classic tokens where possible [19].
He removes auto-merge for agent-authored PRs, adds an Ask rule for any
change under .github/workflows/, and adds the poisoned
issue to the agent’s evaluation suite so a regression would be caught
before deployment.
The trigger was injected text. The damage came from a write token scoped to the whole organisation and an auto-merge with no human in front of it.
Post-incident review template
Keep it blameless and specific:
- Timeline in UTC from first trigger to containment, with sources for each entry.
- Which of the five mechanisms applied, and which control would have stopped each step.
- Revocation latency observed versus expected.
- What evidence was missing, and what logging change fixes that.
- Permission changes made, with before and after grants.
- New evaluation cases added (the actual malicious input, sanitised).
- Notification decisions and reasoning.
Key takeaways
Treat out-of-brief behaviour as a recurring incident class with five mechanisms (capability failure, indirect injection, excessive agency, tool compromise and confused deputy), and expect injection to be the trigger and excessive agency the amplifier. Stopping the agent loop, revoking credentials and cutting egress are separate levers that close different paths. Your real exposure window is the token’s remaining lifetime if resource servers validate locally, or the shorter of that lifetime and the introspection cache interval if they check status, so measure it in advance. Capture transcripts, triggering content, tool definitions as served and credential identifiers before anyone cleans up, with UTC timestamps and integrity protection. Enforce the kill switch and every permission outside the model, at a gateway or resource server the agent cannot argue with. Close each incident by narrowing grants and adding the triggering input to an evaluation suite, which is how NIST’s improvement loop becomes concrete for agents.
primitive’s work sits in the Protect and Respond rows of this table: per-agent grants that are narrow by default and revocable in one place.
Sources and further reading
- Greshake, K., Abdelnabi, S., Mishra, S., Endres, C., Holz, T., & Fritz, M. (2023). Not what you’ve signed up for: Compromising Real-World LLM-Integrated Applications with Indirect Prompt Injection. Proceedings of the 16th ACM Workshop on Artificial Intelligence and Security (AISec ’23), 79–90. https://doi.org/10.1145/3605764.3623985 (preprint: https://arxiv.org/abs/2302.12173)
- OWASP Gen AI Security Project. (2025). LLM06:2025 Excessive Agency (OWASP Top 10 for LLM Applications 2025). OWASP Foundation. https://genai.owasp.org/llmrisk/llm062025-excessive-agency/
- Invariant Labs. (2025, 1 April). MCP Security Notification: Tool Poisoning Attacks. Invariant Labs blog. https://invariantlabs.ai/blog/mcp-security-notification-tool-poisoning-attacks
- Radosevich, B., & Halloran, J. (2025). MCP Safety Audit: LLMs with the Model Context Protocol Allow Major Security Exploits. arXiv preprint arXiv:2504.03767. https://arxiv.org/abs/2504.03767
- Hardy, N. (1988). The Confused Deputy (or why capabilities might have been invented). ACM SIGOPS Operating Systems Review, 22(4), 36–38. https://doi.org/10.1145/54289.871709 (archived open copy: https://web.archive.org/web/2023/http://cap-lore.com/CapTheory/ConfusedDeputy.html)
- Model Context Protocol. (2026). Security Best Practices (documentation for protocol revision 2026-07-28). https://modelcontextprotocol.io/docs/2026-07-28/tutorials/security/security_best_practices
- Ruan, Y., Dong, H., Wang, A., Pitis, S., Zhou, Y., Ba, J., Dubois, Y., Maddison, C. J., & Hashimoto, T. (2023). Identifying the Risks of LM Agents with an LM-Emulated Sandbox. arXiv preprint arXiv:2309.15817. https://arxiv.org/abs/2309.15817
- Debenedetti, E., Zhang, J., Balunović, M., Beurer-Kellner, L., Fischer, M., & Tramèr, F. (2024). AgentDojo: A Dynamic Environment to Evaluate Prompt Injection Attacks and Defenses for LLM Agents. arXiv preprint arXiv:2406.13352. https://arxiv.org/abs/2406.13352
- Nelson, A., Rekhi, S., Souppaya, M., & Scarfone, K. (2025). Incident Response Recommendations and Considerations for Cybersecurity Risk Management: A CSF 2.0 Community Profile (NIST SP 800-61r3). National Institute of Standards and Technology. https://csrc.nist.gov/pubs/sp/800/61/r3/final
- Joint Task Force. (2020). Security and Privacy Controls for Information Systems and Organizations (NIST SP 800-53 Rev. 5), controls IR-4 and AU-3. National Institute of Standards and Technology. https://csrc.nist.gov/pubs/sp/800/53/r5/upd1/final
- Willison, S. (2025, 16 June). The lethal trifecta for AI agents: private data, untrusted content, and external communication. Simon Willison’s Weblog. https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/
- OpenTelemetry. (2026). Semantic conventions for generative AI systems (Development status). OpenTelemetry GenAI semantic conventions repository. https://github.com/open-telemetry/semantic-conventions-genai
- Lodderstedt, T. (Ed.), Dronia, S., & Scurtescu, M. (2013). OAuth 2.0 Token Revocation (RFC 7009). IETF. https://www.rfc-editor.org/rfc/rfc7009
- Richer, J. (Ed.). (2015). OAuth 2.0 Token Introspection (RFC 7662). IETF. https://www.rfc-editor.org/rfc/rfc7662
- Lodderstedt, T., Bradley, J., Labunets, A., & Fett, D. (2025). Best Current Practice for OAuth 2.0 Security (RFC 9700). IETF. https://www.rfc-editor.org/rfc/rfc9700
- Australian Signals Directorate’s Australian Cyber Security Centre and co-authors. (2024). Best practices for event logging and threat detection. Australian Signals Directorate. https://www.cyber.gov.au/publication/best-practices-for-event-logging-and-threat-detection
- Model Context Protocol. (2026). Local Server Security (documentation for protocol revision 2026-07-28). https://modelcontextprotocol.io/docs/2026-07-28/tutorials/security/local-server-security
- Office of the Australian Information Commissioner. (2025). Data breach preparation and response, Part 4: Notifiable Data Breach (NDB) Scheme. OAIC. https://www.oaic.gov.au/privacy/privacy-guidance-for-organisations-and-government-agencies/preventing-preparing-for-and-responding-to-data-breaches/data-breach-preparation-and-response/part-4-notifiable-data-breach-ndb-scheme
- GitHub. (2026). Managing your personal access tokens. GitHub Docs. https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens