Back to blog
Sandboxes and Browsers for AI Agents: Isolation and Disposable Sessions
Engineering7 min read • Dec 4, 2026

Sandboxes and Browsers for AI Agents: Isolation and Disposable Sessions

An agent that runs code and browses the web needs an isolated environment: what a sandbox gives you, what E2B and Browserbase solve, and how to choose.
Diego Velez
Diego Velez
Technical leadership

The agent needs hands, and hands need a safe place

There is a moment in every agent project when conversation stops being enough. The agent has to do things: run the code it just wrote to see if it works, run the tests, open a page that has no API, fill in a form, download a file and extract its data. In other words, it needs an execution environment and, increasingly, a browser.

The engineering question is not whether to give it those capabilities — without them, most useful agents don't exist. The question is where it executes them. And the most common wrong answer is: in the same environment where your application runs, with your credentials, your network, and your filesystem.

An agent generates code nobody reviewed and browses sites nobody chose. Giving it your production machine (or your dev laptop, which amounts to the same thing in terms of credentials) is the equivalent of routinely running scripts downloaded from the internet as your own user. It will work out sometimes. The design cannot depend on that.

What a sandbox actually gives you

An agent sandbox is an isolated environment, created per task or per session, where the agent can run code and use tools with a limited blast radius. What it provides is not magic; it is four concrete properties:

  • Isolation. The agent's code runs separated from your application, your data, and your real credentials. If the code is wrong — or was induced by a prompt injection — the damage stays inside the box.
  • Disposable sessions. Each task can start in a clean environment and be destroyed when it ends. Nothing persists between sessions except what you deliberately export: no files, no zombie processes, no half-finished "configuration" the agent left behind.
  • Hard limits. CPU, memory, execution time, and network egress are set outside the agent, in the infrastructure. The agent cannot negotiate them, because they are not in its prompt: they are in the system that contains it.
  • Reproducibility. If the environment is defined the same way every time (same image, same dependencies), a failed run can be repeated under the same conditions. Without this, debugging an agent that fails "sometimes" is guesswork.

E2B and Browserbase: the two halves of the problem

In practice, the market has sorted itself into two categories, and it helps not to confuse them.

E2B solves the code-execution half: isolated sandboxes that start fast, designed for an agent to write code, run it, observe the result, and iterate. It is the pattern behind most coding agents and agents that process data with scripts generated on the fly. The homegrown alternative — containers you orchestrate yourself — works, but fast per-session startup, strong isolation, and automatic cleanup are exactly the laborious part of building it.

Browserbase solves the browser half: managed Chromium instances in the cloud, operable by an agent, with observable sessions (you can see what the browser did, step by step) and designed to run many in parallel without you maintaining the browser farm. The homegrown alternative — a headless Chromium on your server — is fine for an experiment and becomes a maintenance job as soon as you need concurrency, persistent sessions, or dealing with sites that block basic automation.

An honest warning about the browser half: operating third-party sites with agents collides with reality — bot detection, captchas, terms of service that prohibit automation. A browser service reduces the technical friction, but it does not make legitimate or stable what the target site decided to block. Before designing an agent that "operates such-and-such portal," verify that the portal allows it or that an official path exists. If there is one (an API, an integration), it is almost always better than the browser.

Use cases where the sandbox is not optional

  • Agents that write code. Writing code without running it is writing blind: the write → run → read the error → fix cycle needs a place to run, and that place cannot be the production repository or the developer's machine with its SSH keys.
  • Agents that operate sites with no API. Government portals, legacy systems, vendor dashboards: some flows only exist as web pages. The agent browses in an isolated session, with the credentials for that portal and nothing else.
  • Data extraction and processing. Downloading documents, running transformation scripts, processing files that come from outside. Every external file is, by definition, untrusted input: it gets processed inside the box.
  • Evaluation and testing. Running the same task dozens of times in identical environments to measure the agent (or to attack it, in a red team) is only practical if environments create and destroy themselves.

In our guide to building an agentic system we describe the agent's basic loop; the sandbox is where that loop touches the world. The rule fits in one sentence: the agent can reason wherever you want, but it acts inside a box you control.

Build your own sandbox or use a service? Criteria

| Criterion | Service (E2B, Browserbase) | Your own (your containers/browsers) | |---|---| | Time to working | Hours; the orchestration already exists | Weeks; startup, isolation, and cleanup are your problem | | Cost | Per session/usage; predictable early, grows with volume | Fixed infrastructure; cheap at high volume if you already have the platform | | Isolation | Strong and maintained by the provider | As strong as what your team implements and maintains | | Data and compliance | Sessions run outside your infrastructure; review what data passes through | Everything stays inside your perimeter | | Maintenance | The provider's | Yours, forever: images, patches, capacity, cleanup |

The practical read: start with a service unless you have a concrete reason not to (data that cannot leave, volume that makes per-session cost absurd, a container platform already mature in-house). Building the sandbox layer is an infrastructure project in its own right, and almost no team needs it as its own project at the start. What cannot be delegated in any case is the design of what goes into and out of the box: which credentials each session receives, which network it can reach, and which results get persisted. That is your architecture, whichever service you use.

And the second warning, to close the loop: the sandbox contains, it does not absolve. An agent holding a valid credential inside the sandbox can still do legitimate-looking damage — spending, sending, modifying — if its governance is poor. Isolation without least privilege and limits is just a more comfortable box to make mistakes from.

Conclusion

Giving an agent the ability to run code and browse is giving it hands. The engineering is in deciding which room those hands work in: isolated, disposable, with limits the agent does not control, and a record of what it did. E2B and Browserbase exist because building that room well is more work than it looks; using them (or building your own) is a decision about cost, data, and maintenance, not fashion.

At SolarDevs we run agents that execute real actions — over monitoring and infrastructure — and the scoped environment is part of the base design, alongside least privilege and the complete trace. If you are designing where your agent will act and want to review that architecture before it acts in the wrong place, let's talk. It is cheaper to move the box now than to clean up later.

Need someone to run this?

DevOps retainers with infrastructure monitoring, CI/CD, and clear monthly packages—from $500/mo.

See pricing