AI agent security, also called agentic AI security, is the practice of limiting what an AI agent can read, run and reach, so that a fooled or mistaken model can't turn into a damaged system. It uses the controls you'd apply to any untrusted workload: least privilege, isolation, egress control and audit trails. What's different is that the process picks its next action from text it has never seen before.
Agents act on their output. A wrong decision becomes a shell command, an API call, a commit or a change to cloud resources. This page covers the agent threat model, how agentic AI security differs from securing a chatbot or a plain LLM app, the main risks mapped to the OWASP Top 10 for LLM Applications, the controls that limit damage when the model is fooled, and a hands-on example on Ubuntu 24.04.
Why agents change the threat model
Most LLM security guidance starts with the model's answers. An agent differs from a chatbot in four ways: it holds credentials, calls tools and APIs, runs code and reads content nobody vetted. It also works in a loop: read text, choose a tool call, run it, read the result, choose again. Any text in that loop can steer the next action, and the model has no reliable way to tell instructions from data.
That's the root of prompt injection. Direct injection comes from the person typing. Indirect injection arrives inside content the agent reads on its own: a web page, a README, an issue comment, an email or a tool's output. OWASP's 2026 list describes indirect injection as external content carrying instructions the user neither wrote nor saw, and states that no reliable prevention mechanism exists today.
That puts the controls outside the model. Treat the agent like untrusted code: a quarantined agent in an isolated environment, with a narrow, logged path to the trusted environment that holds your credentials, data and production systems.
Simon Willison's lethal trifecta is a useful test for exfiltration risk. An agent with access to private data, exposure to untrusted content and the ability to communicate externally can be tricked into sending that data to an attacker. Avoid giving one agent all three.
How agentic AI security differs from LLM app security
Agentic AI security deals with models that act. An agent calls tools, runs code, writes to APIs, keeps memory between sessions and carries out multi-step plans, sometimes together with other agents. Its main risks come from those actions, so its controls limit what the agent may do, what it remembers and how far one agent's output can travel.
A chatbot or a plain LLM app returns text to a person, who decides what to do with it. An agent carries out its own output, so a wrong or manipulated answer can become a changed record, a sent payment or a deleted branch.
Property | Chatbot or plain LLM app | AI agent |
|---|---|---|
What the output becomes | Text that a person reads | Tool calls, code runs, API writes, commits |
Credentials | The app's own, used by fixed app code | Keys, tokens and roles used by whatever the model decides to do |
Steps per request | One response | A loop of steps the model plans as it goes |
State | Chat history for the session | Long-term memory and retrieval stores reused across sessions |
Other agents | None | May delegate to other agents or take their output as input |
The agentic AI security risks below follow from that difference. Two documents from OWASP's Agentic Security Initiative cover them: the OWASP Agentic AI Threats and Mitigations guide, first published in February 2025, and the OWASP Top 10 for Agentic Applications for 2026, published in December 2025.
Start with excessive agency, where the agent has more tools, permissions or autonomy than its task needs. It's LLM03 in the 2026 Top 10 for LLM Applications, and the agentic Top 10 expands on the concept with a principle it calls least agency. An agent can also do harm with nothing beyond the tools it's allowed. After an injected instruction, an ambiguous request or unsafe delegation, it may use one of them in a harmful way, and a cleanup tool pointed at the wrong directory needs no extra permissions to do damage. OWASP lists this tool misuse as ASI02 Tool Misuse and Exploitation.
Identity and memory carry their own risks. An agent can inherit a person's or service's role, keep delegated access after the task ends, or expose a token that someone else then uses; that privilege compromise falls under ASI03 Identity and Privilege Abuse. With memory poisoning, an attacker writes false or malicious data into the agent's long-term memory or retrieval store. Later sessions trust that data, so one injection can steer decisions long after it happened, and for other users when the memory is shared. This is ASI06 Memory & Context Poisoning.
Multi-agent systems add cascading actions. One agent's wrong or manipulated output becomes another agent's input, and each agent acts on it in turn. If the messages between agents aren't authenticated, an attacker can inject or spoof steps along the way. OWASP covers this in two entries, ASI07 Insecure Inter-Agent Communication and ASI08 Cascading Failures.
NIST's Center for AI Standards and Innovation (CAISI) describes agents the same way. Its January 2026 request for information describes AI agent systems as "capable of planning and taking autonomous actions that impact real-world systems or environments", and a May 2026 NIST summary of the responses reports broad agreement that agents present new security threats.
Securing AI agents still starts with the host underneath them. The hardening in Container Security Basics applies to any container an agent's code runs in.
AI agent security risks
The OWASP Top 10 for LLM Applications is the common reference list, and its 2026 edition came out in August 2026. The table maps each agent threat to its closest OWASP entry and to the controls below that limit it.
Threat | What it looks like in an agent | Controls that limit it | OWASP 2026 |
|---|---|---|---|
Direct prompt injection | A user tells a support agent to ignore its rules and issue a refund | Least privilege, human approval | LLM01 Prompt Injection |
Indirect prompt injection | A comment in a pull request tells a coding agent to add an SSH key | Least privilege, human approval, egress control, red-teaming | LLM01 Prompt Injection |
Tool misuse and excessive permissions | An agent that reads orders holds a role that can drop tables | Least privilege, narrow tools | LLM03 Excessive Agency |
Data exfiltration | The agent puts file contents into a URL it was told to fetch | Egress control, audit logging | LLM02 Sensitive Information Disclosure |
Credential theft | Generated code reads environment variables, the cloud metadata address or a key in the system prompt | Short-lived credentials, secrets outside the sandbox, egress control | LLM02, LLM08 Hidden Context Exposure |
Malicious or hallucinated packages | The agent installs a package name the model invented and an attacker registered | Pinned package sources, sandboxing, egress control | LLM04 Supply Chain |
Runaway cost and loops | A retry loop burns the API budget overnight | Rate and spend limits, audit logging | LLM06 Unbounded Consumption |
Unsafe code execution | Model output reaches a shell, or a generated script runs next to deploy keys | Sandboxing, resource limits, output validation | LLM10 Improper Output Handling |
Excessive agency makes every other risk on this list worse. OWASP lists three root causes: excessive functionality, excessive permissions and excessive autonomy. If the agent has no tool that can carry out an injected instruction, the injection can't do damage.
AI agent security controls
Each control below assumes the model will be fooled at some point. None of them covers every risk, so use several together.
Least privilege, credentials and tools
Give each agent its own identity: its own service account, API keys and database role. Scope each credential to the actions the task needs, and prefer tokens that expire in minutes or hours over long-lived keys. Never let an agent borrow a person's credentials, because the logs then can't separate the agent's actions from the person's.
Keep those credentials where the model can't see them. Anything in the context window can be repeated back, and code inside the sandbox can read anything the sandbox holds, so keys don't belong in system prompts, tool descriptions or sandbox environment variables. Put a tool broker in the trusted environment that attaches credentials to outbound calls, so the agent requests an action and never sees the key.
The same thinking applies to tools. Expose a short list of narrow tools instead of a general shell or a generic HTTP client: a create_ticket tool with fixed fields is easier to reason about than run_command. For destructive or hard-to-reverse actions, such as deleting data, moving money or changing access policies, require a person to approve the specific call with its full arguments. OWASP recommends this human-in-the-loop check for high-impact actions. Keep approvals to those actions, because when every call needs approval, people stop reading the requests.
Sandboxing, egress and resource limits
Code the agent writes or downloads belongs in a quarantined environment with no ambient credentials: no cloud role, no SSH agent, no mounted home directory and no tokens in environment variables. Options range from an unprivileged user with systemd sandboxing, to a container built on namespace isolation and a tight seccomp profile, to a microVM with its own kernel. What Is Sandboxing? compares these boundaries and what each one stops.
The sandbox needs a network boundary as well. Deny outbound traffic from the quarantined agent by default and allow only the endpoints it needs, and block the cloud metadata address, 169.254.169.254. On AWS, applications on an instance fetch the instance role's temporary credentials from that address. Watch DNS too, since a resolver that forwards any name can carry data encoded in the names it looks up. IP allow lists also break when an API's addresses change, so for HTTPS APIs, send the agent through a forward proxy that allows specific hostnames, and let the firewall permit only the proxy.
Package installs need the same care, because models invent package names. A USENIX Security 2025 study of 576,000 generated code samples found that at least 5.2% of the packages commercial models suggested didn't exist, and 21.7% for open-source models, on average. OWASP's LLM04 entry calls registering those names in advance "slopsquatting". Let agents install only from an internal mirror or a lockfile with pinned versions and hashes, and keep public registries off the egress allow list.
Then cap what a task can consume. Limit tokens, tool calls, wall-clock time and money per task and per day, and alert before the cap. On the execution side, cgroup limits on memory, CPU and process count stop generated code from starving the host.
Filtering, audit logging and red-teaming
Filters catch known patterns: injection phrasing, secrets in responses, links to unknown domains, shell metacharacters in arguments. Treat model output as untrusted input to the next system, which means validating tool arguments against a schema, using parameterized queries and never passing model text to a shell. Filters are probabilistic, so use them alongside the other controls. Willison points out that in web application security, stopping 95% of attacks is a failing grade.
Log every tool call with its arguments, the identity it ran as, its result and the input that led to it, and ship the logs out of the sandbox to a store the agent can't write to. After an incident, that trace shows which input made the agent act.
Before an incident, test the agent the way an attacker would. Plant instructions in the documents, pages and tool outputs it reads, and check whether it acts on them. Try to make it reveal its system prompt, call a tool outside its task or reach a host outside its allow list. Keep these cases as a regression suite and re-run it whenever the model, prompt or tool list changes.
Hands-on: quarantine an agent's tool commands
This example runs an agent's tool commands as an unprivileged user, limits that user's outbound traffic with nftables and runs generated code in a systemd sandbox. It assumes Ubuntu 24.04 with systemd-resolved, the default resolver, plus nftables and dig (sudo apt install nftables bind9-dnsutils).
api.example.com at 203.0.113.10 stands in for the one API the tools may call, and paste.example.net for the place an injected instruction tries to send data. Replace both with your own.
Step 1: Create the agent user
sudo useradd --system --home-dir /srv/agent-work --shell /usr/sbin/nologin agentsudo install -d -o agent -g agent -m 0750 /srv/agent-workThe agent's tool runner executes as this user. It has no login shell, no sudo rights and one writable directory.
Step 2: Write the egress allow list
Create /etc/nftables-agent.nft:
table inet agent_egressdelete table inet agent_egress
table inet agent_egress { set allowed_v4 { type ipv4_addr flags interval elements = { 203.0.113.10 } }
chain output { type filter hook output priority filter; policy accept; meta skuid "agent" jump agent_out }
chain agent_out { ip daddr 127.0.0.53 meta l4proto { udp, tcp } th dport 53 accept ip daddr @allowed_v4 tcp dport 443 accept log prefix "agent-egress-deny " counter reject with icmpx admin-prohibited }}The output chain sends only packets from sockets owned by agent to agent_out, so other users aren't affected. nft turns "agent" into its numeric UID when it loads the file, which is why the user has to exist first and why you reload after recreating it. The first two lines make the file safe to reload.
Inside agent_out, DNS is allowed only to the systemd-resolved stub on 127.0.0.53. That stub still forwards any name upstream, so high-risk agents need a resolver that answers only allowed names. HTTPS is allowed only to addresses in allowed_v4, and everything else is logged and rejected, including IPv6 and the metadata address. Rejecting instead of dropping makes a blocked call fail at once instead of timing out.
Load it, then make it persistent by including it from the main ruleset:
sudo nft -f /etc/nftables-agent.nftecho 'include "/etc/nftables-agent.nft"' | sudo tee -a /etc/nftables.confsudo systemctl enable --now nftablesUbuntu's default /etc/nftables.conf starts with flush ruleset. If the host's firewall is managed by another tool, load the agent file from that tool's startup instead, so the two don't overwrite each other.
Step 3: Test allowed and blocked calls
sudo -u agent curl -sS -o /dev/null -w '%{http_code}\n' https://api.example.com/sudo -u agent curl -sS --max-time 5 https://paste.example.net/sudo -u agent curl -sS --max-time 5 http://169.254.169.254/latest/meta-data/sudo -u agent dig +short +tries=1 +timeout=2 @1.1.1.1 example.com200curl: (7) Failed to connect to paste.example.net port 443 after 33 ms: Couldn't connect to servercurl: (7) Failed to connect to 169.254.169.254 port 80 after 10 ms: Couldn't connect to server;; communications error to 1.1.1.1#53: host unreachable;; no servers could be reachedThe API call succeeds. The paste site, the metadata address and an outside DNS server are refused at once. Run the paste curl as your own user and it connects, which confirms the rules apply only to agent.
Every rejection is counted and logged with its destination address and port:
sudo nft list chain inet agent_egress agent_outsudo journalctl -k --grep agent-egress-deny -n 3Step 4: Run generated code in a systemd sandbox
Save this as /srv/agent-work/task.py. It stands in for code an agent wrote:
import pathlib
def attempt(label, action): try: action() print(f"{label}: allowed") except OSError as err: print(f"{label}: blocked ({err.strerror})")
attempt("write /srv/agent-work/out.txt", lambda: pathlib.Path("/srv/agent-work/out.txt").write_text("ok\n"))attempt("write /etc/agent-test", lambda: pathlib.Path("/etc/agent-test").write_text("x\n"))attempt("list /home", lambda: list(pathlib.Path("/home").iterdir()))print("allocating 1 GiB", flush=True)data = b"x" * (1024 ** 3)print("allocation finished")Run it as agent in a transient systemd unit with file system and resource limits:
sudo systemd-run --wait --pipe --collect \ --uid=agent --gid=agent \ -p WorkingDirectory=/srv/agent-work \ -p ProtectSystem=strict -p ProtectHome=yes -p PrivateTmp=yes \ -p ReadWritePaths=/srv/agent-work \ -p NoNewPrivileges=yes -p PrivateDevices=yes \ -p MemoryMax=256M -p MemorySwapMax=0 -p TasksMax=32 -p RuntimeMaxSec=120 \ python3 /srv/agent-work/task.pyRunning as unit: run-u3.service; invocation ID: 3eb7b40f779a4a0cae924454c4784c47write /srv/agent-work/out.txt: allowedwrite /etc/agent-test: blocked (Read-only file system)list /home: blocked (Permission denied)allocating 1 GiBFinished with result: oom-killMain processes terminated with: code=killed/status=KILLService runtime: 1.778sCPU time consumed: 1.660sMemory peak: 256.0MMemory swap peak: 0BProtectSystem=strictmakes the whole file system read-only for the unit, andReadWritePaths=reopens the work directory.PrivateTmp=yesgives it a private/tmp.ProtectHome=yeshides/home,/rootand/run/user. Without the sandbox,agentcan list/home.NoNewPrivileges=yesstops setuid programs such assudofrom raising privileges, andPrivateDevices=yeshides physical devices.MemoryMax=,MemorySwapMax=,TasksMax=andRuntimeMaxSec=cap memory, swap, process count and wall time. The 1 GiB allocation hit the 256M cap and the kernel killed it.
The unit runs as agent, so the nftables rules apply inside it too.
Running agents in production
The example covers one host and one user. In production, give each agent task its own AI sandbox, an isolated environment you throw away when the task ends, so nothing an attacker plants survives into the next run. Credentials come from a broker in the trusted environment and expire with the task.
A dedicated user and systemd sandboxing share the host kernel, so a kernel exploit crosses that boundary. For code from unknown sources, use a boundary with its own kernel. gVisor runs an application kernel in user space, and Firecracker uses KVM to run each workload in a microVM.