Skip to content

AI Agent Security: Sandboxing and Permissions

Published Updated

AI agent security limits what an agent can read, change and send when it uses your systems. Run code in an isolated environment, give the agent its own identity and enforce permissions where each action happens. Before launch, verify that the agent can do the job and that your team can stop it.

Why Agents Need Their Own Security Controls

An AI agent can change a record, send a message or commit money by calling a tool. A mistaken decision can have the same effect as an instruction changed by prompt injection. The agent’s access determines how far the damage can spread.

The Open Worldwide Application Security Project (OWASP) lists Excessive Agency as LLM06 in its Top 10 for Large Language Model Applications. It covers agents with more tools, permissions or freedom to act than the job requires. An agent that prepares a record for review needs a way to save the draft. The separate permission to publish that record belongs with whoever approves it.

Sandboxing Agents

An AI sandbox is an isolated environment where an agent can run code or tools within limits set by the operator. A container or virtual machine can provide that environment. Containers share a host kernel. The NIST guide to container security explains the isolation risks this creates. Consider a virtual machine when the agent runs untrusted code and the workload needs a stronger boundary from the host.

Set the sandbox limits around what the job needs:

  • Restrict outbound network access to approved destinations. Disable it for jobs that can finish using local inputs. Enforce the restriction outside the agent, including at any tool service that can make requests on its behalf.
  • Use a fresh environment for each job when agents run code from users or handle data for different customers. Dispose of the environment after the job. Put any approved output in a separate store with its own access controls.
  • Mount only the files the job needs, in read-only mode where possible. Give the agent a separate scratch directory for temporary work and keep host files and credentials outside its reach.

A sandbox limits where code can run and what it can reach. A connected service still needs to enforce its own permissions when the agent sends it a request.

Permissions and Least Privilege

Grant the agent access to specific tools and records for a named job. List each action the job requires and the system that must enforce it. Give read access by default where the job is to find or summarise information. Where a write is necessary, allow only the operations and resources the job needs. Enforce those limits at the tool or destination service as well as in the agent’s tool list.

Use scoped, short-lived tokens issued for the intended service and action. When the agent acts on a user’s behalf, check that the user and the agent are both allowed to perform the requested action. Set limits on transaction amounts or the number of actions per job outside the model.

Consider an agent that drafts refunds. It can read an eligible order and prepare a proposed refund. A human-in-the-loop approval shows the approver the exact order, recipient and amount before a separate service executes the refund. The approval applies to that one action. A changed amount needs a new decision, and a retry must never issue a second refund.

Agent Identity and Credentials

Give each deployed agent its own workload identity, an account used by software. Keep test and production identities separate. A dedicated identity shows which agent acted and lets administrators change or revoke its access without disabling a staff account or unrelated agents. Record the initiating user as well when the agent acts on someone’s behalf.

Microsoft Entra Agent ID lets administrators disable individual agent identities. Amazon Bedrock AgentCore Identity has workload identities and can use identity and access policies to limit which credential providers an agent can use. Google Cloud’s Agent Identity gives supported agents a dedicated cryptographic identity in Gemini Enterprise Agent Platform. Keep the same separation of duties when using a dedicated service account for a custom agent.

Use a secrets manager for any credentials the agent’s runtime or tools need. Keep them out of prompts, source code and logs. Prefer credentials issued on demand, and rotate remaining long-lived secrets and revoke superseded ones. Review access when the agent’s job changes and remove its identity when you retire it.

MCP Servers and Tool Connections

Review each Model Context Protocol (MCP) server and third-party tool before connecting it. A compromised server can advertise a poisoned tool description that misleads an agent about what the tool does. A legitimate server can also expose more tools or request more data access than you need.

Check the publisher, where the server runs and what data it can read or send. Compare the permissions it requests with the specific tools you intend to expose. Pin reviewed versions for software you deploy. For hosted servers, review changes to the exposed tools and permissions before enabling them. Limit the server’s own downstream access so it cannot use broader permissions than the agent needs.

The MCP authorisation specification defines an OAuth-based flow for protected HTTP connections. Under that flow, the server must check that the token was issued for it. Give the connection only the scopes it needs and use separate credentials when the server calls another service. Apply local process and file permissions to servers that run alongside the client.

Securing the Agents You Build

Log every tool call by agent identity, including calls the service denies. Record the time, tool and action, the records or data categories touched and the result. Include the initiating user, approval reference and request ID where applicable. Store the audit log outside the agent’s write access. Keep credentials and unnecessary sensitive content out of it.

Give the on-call team a shutdown switch they can use without the agent’s cooperation. It must stop new runs and queued work, cancel active runs where possible and block calls at the tool boundary. Disable the identity and revoke credentials where supported. Where an issued token can remain valid until it expires, use the tool service’s own access controls to deny it immediately. Check for actions already committed and use your AI incident response process to contain the effects.

Have the system owner and a security reviewer complete this checklist in an authorised test environment before launch. Use synthetic records, test identities and harmless canaries such as a labelled dummy file reserved for access checks. Replace external sends or payments with test destinations.

  1. Verify that the approved task completes and that the agent identity matches the access record.
  2. Check that the sandbox blocks access to the dummy file and unapproved network destinations. Confirm that job data is absent from the next fresh environment.
  3. Verify that read access cannot change records. Confirm that outside-scope requests are denied and a high-impact action produces no change without approval.
  4. Match a completed call and a denied call to their audit events. Check that the events identify the data touched without storing credentials.
  5. Activate the shutdown switch and verify that new and queued work cannot reach the test service. Review any in-flight calls and record what the switch could cancel.

If a check fails, leave the affected tool disabled, correct the permission, isolation or approval control and repeat the check before restoring access.