AI Agent Security: Risks Across the Agent Lifecycle

Written by

in

Secondary: llm agent security, llm coding agents security, security for llm

A chatbot answers questions. An agent acts: it reads files, calls APIs, runs code and sends messages, often with little human review. That shift changes the security problem. A bad answer from a chatbot is a content problem, but a bad action from an agent can be an incident.

This article walks through AI agent security in the order a team meets it: design, tool use, then deployment and operations. If you are new to the topic, our overview of AI agents covers the basics.

Image 1 – lifecycle diagram. Alt text: “Diagram of the AI agent lifecycle showing design, tool use, deployment and monitoring stages with security risks at each stage”

Why agents widen the attack surface

Most LLM agent security problems come from one property of language models. They do not reliably separate instructions from data. Text the agent reads, such as a web page, an email or a code comment, can be interpreted as a command.

Researchers described this as indirect prompt injection. Greshake et al. showed that attackers can plant instructions in content an LLM-integrated application later retrieves, without ever talking to the model directly (Greshake et al., 2023). OWASP lists prompt injection as the first risk in its Top 10 for LLM applications, and “Excessive Agency” (an LLM given too much functionality, permission or autonomy) as another (OWASP GenAI Security Project).

Simon Willison’s “lethal trifecta” is a useful mental model. An agent is at serious risk of data theft when it combines access to private data, exposure to untrusted content and the ability to communicate externally (Willison, 2025). Remove any one leg and the risk drops sharply.

Stage 1: Design

Most of the important decisions are made before any code runs.

Define the agent’s job narrowly. A broad “do anything” agent needs broad permissions. A narrow one, such as “triage support tickets and draft replies”, needs few. Write down what the agent must never do as well as what it should do.

Threat-model the data flows. For each agent, ask:

  • What untrusted content can reach the model (web pages, inbound email, uploaded files, tool outputs, other agents’ messages)?
  • What sensitive data can it see?
  • What outward channels does it have (HTTP requests, email, rendered links or images, commits)?

If all three answers are “a lot”, redesign before building. Split the work across agents with different privileges, or put a human approval step on the risky edge.

Decide where humans stay in the loop. Irreversible or outward-facing actions (payments, deletions, external messages, production deploys) are the natural places for approval. Approval has to be informative: showing “Allow tool call?” with no detail trains people to click yes.

Use a shared vocabulary. The NIST AI Risk Management Framework gives governance language for mapping, measuring and managing AI risk (NIST AI RMF). MITRE ATLAS catalogs adversary tactics against AI systems (MITRE ATLAS). Both help security and engineering teams talk about the same threats.

Stage 2: Tool use

Tools are where model output becomes real-world effect, so this is where security for LLM systems looks most like classic application security.

Least privilege, per tool. Give each tool the minimum scope: read-only database credentials where reads are enough, a token limited to one repository, an allowlist of domains the agent may fetch. Don’t reuse a developer’s personal credentials for an agent.

Treat model output as untrusted input. Validate tool arguments against a schema, and never pass model-generated strings straight into a shell, SQL query or file path. This is ordinary injection hygiene applied to a new source.

Treat tool results as untrusted too. A search result or a fetched document may contain instructions. Keep retrieved content clearly separated from instructions in your prompts, and don’t let it silently expand the agent’s permissions.

Be careful with third-party tools and connectors. Every plugin, MCP server or integration you add extends the trusted computing base. Review what it can access, pin versions, and prefer sources you can audit. The Model Context Protocol specification includes security considerations around user consent and tool safety that are worth reading before you connect servers (MCP specification).

Close the exfiltration paths. Even with no “send” tool, agents can leak data through rendered markdown images, link previews or URLs they are allowed to request. Restrict outbound destinations and sanitize rendered output.

Special case: coding agents

LLM coding agents security deserves its own mention because these agents combine file access, shell execution and package installation. Typical concerns include:

  • Malicious instructions hidden in a repository, README, issue or dependency that the agent reads while working.
  • Commands run with the developer’s full local permissions and credentials.
  • Secrets in environment variables or config files being read into the model’s context.
  • Generated code or dependency suggestions that introduce vulnerabilities and get merged unreviewed.

Useful controls: run the agent in a sandbox or container with no access to production secrets, require approval for commands outside an allowlist, keep network access restricted, and review all agent-written changes through your normal code review and CI checks.

Image 2 – tool permission model. Alt text: “Illustration of an AI coding agent running in a sandbox with limited file, network and credential access”

Stage 3: Deployment and operations

A well-designed agent can still fail in production if the surrounding system is loose.

Isolate execution. Run agents in sandboxes with constrained filesystem, network and process access. Assume the model can be manipulated and limit what a manipulated agent can reach.

Manage identity and secrets properly. Give each agent its own identity so actions are attributable and revocable. Keep secrets in a vault and inject them at the tool layer, not in the prompt.

Log everything that matters. Record prompts, tool calls, arguments, results and approvals, with sensitive fields handled according to your data policy. Without a trace you cannot investigate an incident or tell a model mistake from an attack.

Monitor and set limits. Rate-limit tool calls, cap spend and loop depth, and alert on unusual behavior such as unexpected domains, bulk reads or repeated failed actions. Have a kill switch that disables an agent or a single tool quickly.

Test adversarially before and after launch. Include prompt injection cases, poisoned documents and malicious tool outputs in your test suite, and rerun them when you change models, prompts or tools. Model updates can change behavior in ways your earlier tests did not cover.

Plan for multi-agent setups. When agents pass messages to each other, one compromised agent can influence the rest. Treat inter-agent messages as untrusted input, and don’t let low-privilege agents trigger high-privilege actions without a check.

A short checklist

StageQuestion to answer
DesignDoes the agent combine private data, untrusted input and an outbound channel?
DesignWhich actions require human approval?
Tool useIs each tool scoped to least privilege, with validated arguments?
Tool useAre tool results and retrieved content treated as untrusted?
DeploymentIs execution sandboxed, with per-agent identity and secrets in a vault?
OperationsCan you trace every action, alert on anomalies and shut the agent off fast?

Takeaway

No single control makes an agent safe. The reliable approach is layered: limit what the agent can do, limit what it can see, limit where data can go, and keep a human on the actions that cannot be undone. Start by mapping your agent against the three questions in the design stage, then work outward to tools and deployment.

For background on how agents are built and used, see our AI agents page.

Comments

One response to “AI Agent Security: Risks Across the Agent Lifecycle”

  1. […] AI Agent Security: Risks Across the Agent Lifecycle […]

Leave a Reply

Your email address will not be published. Required fields are marked *