# Why AI agents need a sandbox

Lesson 1 of [Agent sandbox foundations for buyers](https://agentsandboxes.fyi/academy/agent-sandbox-foundations.md), 12 minutes.

An AI agent can write code and run it. It can also read web pages, email, issues and uploaded files that you do not control. A sandbox is an isolated environment where that code runs. It puts a boundary between the code and your systems.

## When you need one

Answer each question with yes or no.

- Does the agent write code or shell commands and run them?
- Does the agent read content that you do not control?
- Can the agent reach a network, a database or a file system that holds real data?
- Does more than one person or customer use the same agent?

One yes is enough to use a sandbox. Two or more yes answers mean that the boundary must be strong, not only present.

## What a sandbox does and does not do

The OWASP Top 10 for LLM Applications (2025) names risks that apply to agents. Three of them matter most here:

- **Prompt Injection (LLM01)**: input, including text from a web page or a file, changes the behaviour of the model in ways you did not intend.
- **Excessive Agency (LLM06)**: the system has more functions, permissions or autonomy than it needs, so a bad output can cause damage.
- **Unbounded Consumption (LLM10)**: use of resources without control, which can cause outages or high costs.

A sandbox does not stop a prompt injection. It limits what a successful injection can reach. It also helps limit agency, because the code can only touch what you put inside the boundary. Time, CPU and memory limits on the sandbox help control consumption.

## Two questions for every evaluation

1. What can code inside the sandbox reach? Think of files, network hosts, credentials and other tenants.
2. What stops it when something goes wrong? Think of time limits, resource limits and a way to delete the sandbox.

The next lesson explains the walls that providers use to answer the first question.

## Sources

- OWASP Top 10 for LLM Applications 2025, genai.owasp.org
- AgentSandboxes, The Agent Sandbox Starter Checklist

Also on the [web page](https://agentsandboxes.fyi/academy/agent-sandbox-foundations/why-agents-need-a-sandbox).
