AI Security
How to Secure AI Agents That Have Tool Access
An AI agent that can send email, query databases, or call APIs is a new kind of privileged user, one that can be talked into things. Here is how to design agents that stay safe even when the model is fooled.
EclipticLink Security Team8 min read
A chatbot that answers questions can embarrass you. An AI agent that can send emails, update records, run code, or call your APIs can do real damage. The moment you give a language model tools, it becomes a privileged user of your systems, and unlike a human employee, it can be persuaded by any text it reads.
This guide covers how to design agents that stay safe even when the model makes a mistake or is manipulated, because with today's models, you have to assume that sometimes it will be.
The core principle: assume the model can be fooled
No system prompt, filter, or model choice reliably prevents prompt injection. So the security question for an agent isn't "can the model be tricked?" but "what is the worst thing that happens if it is?" Good agent security is mostly about making that answer boring.
Design the agent's permissions as if an attacker were writing its instructions, because through injected content, sometimes they are.
Understand excessive agency
The OWASP Top 10 for LLM Applications lists Excessive Agency (LLM06) as a top risk and breaks it into three causes. Almost every agent incident traces back to one of them.
| Cause | What it looks like | Fix |
|---|---|---|
| Excessive functionality | A "read email" integration that can also send and delete | Expose only the specific operations the task needs |
| Excessive permissions | The agent uses an admin or shared service account | Scope credentials to the task and to the current user |
| Excessive autonomy | High-impact actions run with no human check | Require approval for consequential actions |
Eight controls for secure AI agents
1. Give each agent the smallest possible toolset
Build narrow tools for specific jobs instead of generic ones. A tool called get_order_status(order_id) is far safer than run_sql(query) or http_request(url). Every general-purpose tool you remove is a whole class of attack that disappears.
2. Act with the user's permissions, not the agent's
When an agent works on behalf of a user, it should use that user's delegated, scoped credentials. Then it can never access data the user couldn't access themselves. Agents running on a shared, all-powerful service account are a confused-deputy problem waiting to happen.
3. Require human approval for high-impact actions
Sending external messages, moving money, changing permissions, deleting data, and deploying code should need explicit confirmation. Show the user exactly what will happen, including the full recipient list and content, not a summary written by the model.
4. Break the lethal trifecta
An agent that has access to private data, reads untrusted content, and can communicate externally can be steered into leaking that data. If an agent needs to read untrusted content such as inbound email or web pages, remove its ability to send data out, or split the work across separate agents with a strict boundary between them.
5. Validate every tool call in code
Treat the model's tool arguments as untrusted input. Validate them against strict schemas, allow-list values such as domains, recipients, and file paths, and enforce business rules like spending limits in your application, not in the prompt.
6. Sandbox code execution and restrict the network
Agents that write or run code should do so in an isolated, short-lived sandbox with no access to production credentials and restricted outbound network access. Egress controls stop many data-exfiltration attempts even when an injection succeeds.
7. Set limits and a kill switch
Cap the number of steps, tool calls, and spend per task, and rate-limit sensitive tools. Make sure you can disable an agent, or a single tool, instantly without a deployment.
8. Log everything and watch for anomalies
Record prompts, retrieved content, tool calls, arguments, results, and approvals with a trace ID per task. Alert on unusual behavior, such as a support agent suddenly querying billing data or a tool being called far more often than normal. These logs are also essential evidence if something goes wrong.
Test your agents like an attacker would
Before launch and after every change to tools, prompts, or data sources, red-team the agent. Useful test cases include:
- Planting instructions in documents, emails, tickets, and web pages the agent will read.
- Trying to get the agent to call tools outside its intended task.
- Attempting to access another user's data through the agent.
- Trying to bypass approval steps, for example by splitting one harmful action into several harmless-looking ones.
- Checking that limits, sandboxing, and egress controls hold when the model is fully compromised.
MITRE ATLAS, a knowledge base of adversary techniques against AI systems, is a useful reference for building these test scenarios. If your agents connect to tools through the Model Context Protocol, also review our MCP security checklist.
A quick agent security checklist
- Does each agent have only the tools and operations its task needs?
- Does it act with the current user's scoped permissions?
- Do high-impact actions require clear human approval?
- Have you avoided combining private data, untrusted content, and external communication in one agent?
- Are tool arguments validated and business rules enforced in code?
- Is code execution sandboxed and outbound network access restricted?
- Are there step, spend, and rate limits, plus a kill switch?
- Is every action logged and monitored?
EclipticLink's AI and LLM security team designs and red-teams agentic systems, from customer-facing assistants to internal automation agents, so you can ship AI features without handing attackers the keys.
Frequently asked questions
What is excessive agency in AI agents?
Excessive agency is a risk in the OWASP Top 10 for LLM Applications where an agent has more functionality, permissions, or autonomy than its task needs, so a mistake or manipulation can cause real damage.
How do you secure an AI agent that can call tools?
Give it the smallest possible toolset, run it with the user's scoped permissions, require human approval for high-impact actions, validate tool arguments in code, sandbox code execution, restrict network egress, set limits, and log every action.
What is the lethal trifecta for AI agents?
It describes an agent that combines access to private data, exposure to untrusted content, and the ability to communicate externally. Together these let an attacker who can inject text potentially exfiltrate data, so avoid giving one agent all three.
Sources and further reading
- AI agent security
- agentic AI security
- excessive agency
- OWASP LLM Top 10
- LLM tool use
- least privilege
- prompt injection