AI Agent Security: Least Privilege, Egress, Approval
In this article
- Why AI Agents Need Different Security Than Traditional Apps
- The Three Pillars: Least Privilege, Egress Control, and Human Approval
- How to Implement Least Privilege for an AI Agent
- Network Egress: What to Allow and How to Enforce It
- Human Approval: When It Is Required and How to Design It
- Common Pitfalls and Misconceptions
- Costs and Trade-offs of These Controls
- Frequently Asked Questions
Yes, securing AI agents requires least-privilege permissions, strict network egress controls, and human approval for high-impact actions. These three controls work together to limit the damage a compromised or misbehaving agent can cause, and they are now considered baseline requirements for production deployments.
Why AI Agents Need Different Security Than Traditional Apps
Traditional software runs with fixed permissions and predictable network calls. An AI agent, by contrast, takes actions based on natural language instructions and its own reasoning. It can read files, send emails, modify databases, or call external APIs. The danger is that a prompt injection attack—where malicious text hidden in a webpage or document instructs the agent to do something harmful—can turn the agent into a tool for data exfiltration or unauthorized changes. Because the agent's behavior is not fully predictable, you cannot rely on the same trust boundaries you use for a standard web application.
The Three Pillars: Least Privilege, Egress Control, and Human Approval
These three mechanisms address different failure modes. Least privilege limits what the agent can access. Network egress limits where data can go. Human approval limits which actions are irreversible or costly. Together, they create a defense-in-depth posture that assumes the agent will eventually be tricked or make a mistake.
- Least privilege: Grant the agent only the minimum permissions needed for its task. If it only needs to read a specific folder, do not give it write access to the entire filesystem. If it only needs to query one database table, do not give it admin credentials.
- Network egress: Restrict outbound network connections to a denylist of approved domains and IP ranges. An agent that can only reach your internal API and a few trusted external services cannot exfiltrate data to an attacker-controlled server.
- Human approval: Require a human to confirm any action that is destructive, expensive, or irreversible—deleting files, sending emails, transferring money, or changing production configurations. This adds a check against both malicious prompts and simple errors.
How to Implement Least Privilege for an AI Agent
Start by listing every action the agent must perform, then map each action to the minimum permission required. Use dedicated service accounts or API keys, not personal credentials. Apply the principle of separation of duties: a read-only agent should never have write tokens in its environment.
- Create a role or service account that has only the specific permissions the agent needs.
- Scope file access to specific directories, not the whole disk.
- Scope database access to specific tables and operations (SELECT, INSERT, etc.).
- Use short-lived credentials that expire automatically.
- Audit permission usage regularly and revoke anything unused.
A common mistake is granting the agent access to a broad internal API because it is convenient. Instead, build a thin wrapper API that exposes only the few endpoints the agent actually calls. This gives you a single place to enforce rate limits, logging, and validation.
Network Egress: What to Allow and How to Enforce It
Network egress control is about preventing data from leaving your environment to unauthorized destinations. The agent should not be able to make arbitrary HTTP requests. You need a proxy or firewall rule that allows only specific destinations.
For example, if your agent uses a public LLM API, allow traffic only to that API's domain. If it needs to fetch a specific documentation site, allow only that site. Everything else should be blocked. This is a technical control that works even if the agent is fully compromised—it simply cannot reach an attacker's server.
Implementation options include:
- An egress proxy that filters by domain and IP.
- Network policies in Kubernetes or cloud VPCs that restrict outbound traffic.
- DNS filtering that resolves only approved domains.
Be careful with IP-based allowlists because many cloud services use shared IP ranges. Domain-based filtering is usually more practical. Also, consider that some LLM APIs accept custom base URLs; ensure the agent is configured to use your approved endpoint, not a user-supplied one.
Human Approval: When It Is Required and How to Design It
Not every action needs human approval. Reading a file or querying a database is low-risk. Deleting a record, sending a message, or executing a purchase is high-risk. The approval step should be integrated into the agent's workflow, not bolted on as an afterthought.
Design a queue where the agent submits an action for review. The human reviewer sees the proposed action, the context, and the data involved, then approves or rejects it. The agent must wait for the response before proceeding. This is often implemented as a separate service that the agent calls before executing a sensitive operation.
Set a policy for what requires approval:
- Any action that modifies or deletes data.
- Any action that sends external communications.
- Any action that incurs cost (API calls, purchases).
- Any action that changes security settings or user permissions.
The approval step should include a timeout so that pending actions do not block the agent indefinitely. If no one approves within a set time, the action is rejected by default.
Common Pitfalls and Misconceptions
One misconception is that an agent's internal reasoning is secure because it is "sandboxed." Sandboxing limits what the agent can do, but it does not stop prompt injection from causing the agent to misuse its own permissions. The sandbox is necessary but not sufficient.
Another pitfall is over-relying on human approval for everything. If every single action requires a human click, the agent becomes useless. The goal is to automate safe actions and escalate only the risky ones. You must define the boundary clearly and test it.
A third issue is egress control that is too permissive. Allowing "any HTTPS" or a broad cloud provider range defeats the purpose. Be specific. Also, remember that egress control does not stop data from being written to a local file that is later exfiltrated by another process—so combine egress control with least privilege on file writes.
Costs and Trade-offs of These Controls
Implementing these controls adds complexity and latency. Least privilege requires careful permission design and ongoing maintenance. Egress filtering requires a proxy or network policy layer. Human approval introduces a delay for every sensitive action, which can slow down workflows.
The cost is justified for agents that handle sensitive data or take consequential actions. For a simple chatbot that only reads public documentation, you may not need all three. But as soon as the agent can write files, call internal APIs, or send messages, the controls become necessary. The cost of a single data breach or unauthorized action far exceeds the cost of the controls.
There is also an operational cost: you need someone to review approval requests and to audit logs. This is a real job, not an afterthought. Plan for it.
Frequently Asked Questions
Can I rely on the AI provider's built-in safety filters instead?
No. Safety filters are designed to stop the model from generating harmful content, but they do not protect against prompt injection or prevent the agent from taking actions using its tools. The model can be tricked into following instructions embedded in data it reads. Your own security controls are the only reliable defense.
What is the difference between sandboxing and least privilege?
Sandboxing isolates the agent's runtime environment—for example, running it in a container with no network access. Least privilege is about the permissions the agent has within that environment. You need both: a sandbox limits what the agent can reach, and least privilege limits what it can do with what it reaches.
How do I handle an agent that needs to access many different external services?
Create a curated list of approved services and add them to the egress allowlist one by one. For each service, use a dedicated API key with the minimum scope. Do not allow general internet access. If the agent needs a new service, review it and add it explicitly.
What happens if a human approval request is ignored?
Set a default-deny policy with a timeout. If no one approves within a defined period—say 5 minutes—the action is automatically rejected. This prevents the agent from hanging indefinitely and ensures that unapproved actions never execute.
Is human approval required for every action a coding agent takes?
Not every action. For a coding agent, reading files and running tests is low-risk. Creating pull requests, merging branches, or pushing to production should require approval. The threshold depends on your risk tolerance, but a good rule is: if the action is hard to undo or affects others, require approval.