AI agent security is the set of controls that stop an AI agent from being tricked, over-privileged or careless with the tools, data and credentials it can reach. For teams shipping agents, it comes down to four jobs: treat every input as untrusted, give each agent the least access it needs, run agent-written code in a sandbox, and check these controls on every code change.
This guide is for engineering leads who already have an agent in production or close to it. It gives you a threat model organised by layer, the control that closes each gap, and a way to keep those controls from drifting once the team ships weekly.
What AI agent security covers
AI agent security covers what an agent reads, what it decides and what it does. A chatbot that writes a wrong answer produces a bad paragraph. An agent with tool calling can run that wrong answer as a SQL query, a shell command or a payment.
That shift from output to action changes the job. Classic application security asks whether a user can reach data they should not. Agent security asks the same question about a piece of software that takes instructions from text, including text an attacker wrote.
Three properties make agents harder to secure than ordinary services:
- The model decides which tool to call at run time, so you cannot list every code path in advance.
- Instructions and data arrive in the same channel, the prompt, so the model cannot reliably tell them apart.
- Agents chain steps, so one bad decision early in an agentic workflow carries forward into later tool calls.
A threat model for tool-using agents
A useful threat model for an agent maps each place where untrusted text meets a capability. Start with a diagram of your agent: its inputs, the tools it can call, the identity it calls them with, where its code runs and what it remembers. Then mark each arrow where data crosses a trust boundary.
The OWASP Top 10 for LLM Applications names the categories most teams should cover first, including prompt injection, improper output handling and excessive agency. For agents, those categories land on eight layers:
- Input. User messages, retrieved documents, web pages, emails, tickets and tool results. Any of these can carry prompt injection.
- Model output. Text the model produces that flows into SQL, a shell, HTML, an API or another agent.
- Tools. Each tool is a capability. An agent with a
send_emailtool and aread_inboxtool can exfiltrate an inbox. - Identity. The credentials the agent uses. A shared service account means the agent can do more than the user it acts for.
- Execution. Where agent-generated code runs, and what that environment can reach: host files, secrets, the open internet.
- Memory. Long-term stores and retrieval indexes that an attacker can write to today and the agent reads tomorrow.
- Supply chain. Frameworks, SDKs, MCP servers, skills and packages the agent pulls in.
- Approval. Which actions run without a human, and whether the approval matches the exact action that runs.
One combination deserves its own check. If a single agent holds private data, reads untrusted content and has any way to send data out, an attacker who controls the content can steal the data. Break at least one leg of that triangle for every agent you ship.
Controls by layer
Each layer needs one primary control that works even when the model misbehaves. Rely on the model to follow its system prompt and you rely on the part an attacker controls.
Input: separate instructions from data
You cannot filter prompt injection out of text with full reliability. Classifiers and delimiters reduce the rate. They do not remove it.
Design so that injected instructions have little to act on. Tag content by source, keep untrusted content out of the system prompt, and strip tools from any step that only needs to summarise or classify untrusted text. A summariser with no tools cannot be talked into sending anything.
Model output: validate before it executes
Treat model output the way you treat form input from an anonymous user. Parameterise SQL. Pass shell arguments as arrays, never as interpolated strings. Escape HTML. Validate JSON against a schema before acting on it.
When one agent hands work to another, the receiving agent should validate the payload too. Multi-agent systems fail when each agent assumes the previous one already checked.
Tools and identity: least privilege per task
Give each agent its own agent identity, scoped to the user it acts for and the task it runs. An agent that drafts replies needs read access to one thread, not the whole mailbox.
Concrete rules that hold up in review:
- The agent can never do more than the user who triggered it.
- Tokens are short-lived and scoped to named resources.
- Write and delete tools are separate from read tools, so you can grant them separately.
- Every MCP server or agent API you expose is authenticated, scoped to a tenant, rate-limited and logged.
Execution: sandbox agent-written code
Code an agent writes should run in a disposable agent sandbox with no host files, no secrets and no open network. Containers with a read-only root, a fresh filesystem per task and an egress allowlist cover most cases. MicroVMs add isolation when the code is fully untrusted.
Keep model-provider API keys out of the environment the agent's commands run in. If the agent can run env, it can print any key in that environment.
Network: allow domains, deny the rest
An agent that can reach any domain can send your data to any domain. Set an allowlist at the network layer, not in the prompt. A fetch tool that accepts arbitrary URLs is an exfiltration tool with extra steps.
Memory: treat stored context as untrusted
Anything an agent writes to memory, a user or attacker can influence. Record the source of every memory entry, expire entries, and never let retrieved memory grant permissions. A note that says "this user is an admin" should carry zero weight.
Approval: tie the human to the exact action
Human-in-the-loop approval works when the human sees the exact action that will run: the recipient, the amount, the file, the diff. It fails when the approval screen says "Agent wants to continue" and the action changes afterwards.
Require approval for sends, payments, deletes and deploys. Keep the list short. Ask for approval on every step and reviewers click yes without reading, the pattern known as approval fatigue.
Observability: log decisions, not only requests
Log each tool call with its arguments, the identity used, the prompt context that led to it and the result. When something goes wrong, you need to replay why the agent chose that action. Agent observability tooling built on traces makes this practical.
What agent frameworks give you by default
Most agent frameworks, SDKs and MCP tools leave security requirements to the builder. The ARI-42 risk index rates widely used agent building blocks against 42 security requirements, and its pattern is consistent: a built-in default rarely meets a requirement, and partial help usually means a setting that is off by default, in preview or on a paid tier.
Two gaps stand out for a team choosing a stack. Few tools that run agent-generated code sandbox it by default, and several run it on the host. Some tools also pass model-provider API keys to the commands the agent runs.
The practical reading: picking a popular framework does not give you a secure agent. You inherit its defaults, and those defaults lean toward convenience. Audit the settings for sandboxing, key handling and network access before you ship. Treat the agent stack as part of your supply chain, with pinned versions and a patch process.
Enforcing agent security in CI
Controls drift unless something checks them on every change. A developer adds a tool, widens a token scope to unblock a demo, or upgrades an SDK whose defaults changed. None of that shows up in a one-time audit from last quarter.
A CI gate for agent security should check, per pull request:
- New or changed tools and the permissions they request.
- Secrets and provider keys in code, config and agent environments.
- Sandbox and network settings for any code-execution path.
- Dependency changes in the agent stack against known CVEs.
- Approval rules for irreversible actions.
- Model output that reaches SQL, shell or HTML without validation.
Coding agents raise the stakes here. When a coding agent writes a large share of the diff, human reviewers skim more, and AI-generated changes can add a tool or widen a permission without anyone flagging it.
The Motiontic Security Layer (MSL) runs this kind of check on every pull request. It is built on the ARI-42 index, and the team's code stays in its own CI. The team's coding agent collects quoted evidence through the Motiontic MCP, a checker verifies each quote matches the commit, and MSL judges it against ARI-42, 85 rated tools and a weekly CVE feed.
Each run produces a PR comment listing every risk with its fix, a dashboard, and a buyer-ready PDF report. MSL governs development agents and secures AI-native apps. It is built for startups with affordable pricing, and runs either as a direct CI integration or in FDE mode, where a Motiontic engineer sets it up on the client's infrastructure.
Answering an enterprise security review
Enterprise buyers ask about agents in their security questionnaires, and vague answers stall deals. Reviewers in regulated industries such as finance, healthcare and legal want evidence, not policy statements.
Prepare written answers, with evidence, for these questions:
- Does code your agent generates run in a disposable sandbox with no host files, secrets or open network?
- Is model output validated before it reaches SQL, a shell, HTML, an API or another agent?
- Can an agent ever do more than the user it acts for?
- Can your agents reach any domain, or only the ones you allow?
- Do sends, payments, deletes and deploys need human approval tied to the exact action?
- Does any agent hold private data, read untrusted content and have a way to send data out, all at once?
Evidence means a config file, a test, a CI log or a report with dates. Map your answers to frameworks the reviewer already uses: the OWASP list above for risk categories, the NIST AI Risk Management Framework for governance, and MITRE ATLAS for attacker techniques. Teams pursuing SOC 2 or ISO 27001 can reuse the same evidence there.
A rollout order for a small team
A startup with one or two agents in production can cover the largest risks in a few weeks if it works in this order:
- Inventory every agent, its tools, its credentials and where its code runs.
- Move code execution into a sandbox with no secrets and an egress allowlist.
- Split shared service accounts into per-agent, per-user scoped identities.
- Add output validation wherever model text reaches an interpreter.
- Add human approval for the four irreversible action types.
- Turn on tool-call logging with arguments and identity.
- Add a CI check so new changes cannot undo steps 2 to 6.
Sandboxing comes second because it removes the largest class of damage: an injected instruction that runs code on a machine holding your keys. Teams that want hands-on help building agents with these controls from day one can look at Motiontic's agent development services.
FAQ
How are regulated industries handling AI agent security?
Regulated teams in finance, healthcare and legal restrict agents to scoped identities, require human approval for irreversible actions, and keep audit logs of every tool call. They also map controls to frameworks their auditors know, such as the NIST AI RMF, so evidence fits existing reviews.
How do you evaluate an agentic AI platform for security and compliance?
Check its defaults, not its feature list: whether agent code runs sandboxed, whether keys reach agent commands, and whether network egress is restricted. Ask for evidence of each, and check how the vendor handled past CVEs and incidents.
Is prompt injection solvable?
No filter stops prompt injection every time, because instructions and data share one channel. You contain it instead: remove tools from steps that read untrusted text, limit permissions and egress, and require approval for high-impact actions.
What is the difference between AI guardrails and AI agent security?
AI guardrails usually filter model inputs and outputs. AI agent security also covers identity, tool permissions, sandboxing, network egress, memory and the supply chain, which is where most agent incidents cause damage.
How often should agent security be checked?
On every pull request. Agents change when tools, prompts, permissions or dependencies change, and a quarterly audit misses everything shipped in between.
Want to see where your agent stack stands against ARI-42? Book a 20-minute call with Motiontic.



