# What is a sandbox for AI coding agents?

[Learn](/learn) › How agents work

# What is a sandbox for AI coding agents?

A sandbox for an AI coding agent is an isolated environment where the agent can run code without being able to reach anything that matters: your secrets, your network, your production systems or the machine it runs on. It exists for two reasons. It keeps a mistake contained, and it makes the result of a test trustworthy.

## Why an agent needs one

An AI coding agent does more than write text. To be useful it installs packages, runs tests and executes the code it just wrote. Code it wrote a moment ago has been reviewed by nobody.

Without a sandbox, that code runs with whatever access the agent has. If the agent has your environment variables, so does the code. If it can reach the internet, so can the code.

## What a sandbox should block

What

Why it matters

Your secrets

Code under test should never see an API key or a database password

The network

A test should not be able to call out, and nothing in a repository should be able to send data anywhere

The host machine

A broken or hostile script should have nothing to damage

The next run

Each run starts empty, so one result cannot leak into another

A sandbox that blocks only some of these is still useful, and you should know which ones it leaves open.

## The second job: making a result mean something

Safety is the reason most people give for sandboxing. The second reason matters as much for anyone who wants to trust an agent’s work.

A test that passes on a developer’s laptop may pass because of something on that laptop. A test that passes in an empty environment, with the network cut, passed because of the code. That is what makes the result evidence.

## How Bugstack uses its sandbox

Bugstack does [autonomous software maintenance](/autonomous-software-maintenance). When your code crashes, it proves the fix in a sandbox before it opens a pull request. The steps:

1.  **Copy.** Bugstack copies your repository into a sandbox. None of your secrets go with it.
2.  **Install.** Your dependencies are installed from the package registries.
3.  **Cut the network.** Before the first test runs, the network is cut.
4.  **Reproduce.** A tester writes a test that fails on your current code, for the bug’s own reason.
5.  **Fix.** A fixer changes the code. The test has to pass, and the rest of your suite has to stay green.
6.  **Destroy.** The sandbox is destroyed when the fix is done.

The pull request carries the test, so you can run the same proof yourself.

The sandbox runs Python, JavaScript and TypeScript, and Go test suites today. Ruby suites, and suites that need a database or another service running, are not run in it yet; those fixes open for your review.

## Questions to ask of any agent’s sandbox

-   Can code running inside it reach the internet?
-   Can it read any credential, including the agent’s own?
-   Is it thrown away after each task?
-   What happens when a task cannot run inside it? Does the agent stop, or carry on without the isolation?

That last question is the one people forget. Bugstack’s answer: when a bug cannot be reproduced in the sandbox, the pull request says so, and it waits for you.

## Questions

### Is a Docker container a sandbox?

It can be part of one. A container isolates the filesystem and processes, and by default it can still reach the network and whatever secrets you passed in. What makes it a sandbox is what you take away.

### Does a sandbox make an AI agent safe?

It makes one kind of mistake harmless: code doing damage while it runs. It does not make the code correct. For that you need a test that fails before the change and passes after it.

### Why cut the network if the code is only running tests?

Because installing a package and running a test are two of the easiest ways for code in a repository to send data somewhere. Cutting the network before the first test removes that path.

## Related

-   [How to verify AI-generated code before it merges](/learn/verify-ai-generated-code)
-   [Is AI-generated code reliable?](/learn/is-ai-generated-code-reliable)
-   [Can AI maintain software?](/learn/can-ai-maintain-software)
-   [What is autonomous software maintenance?](/autonomous-software-maintenance)

## See it work on your own code.

$100 a month

Includes $100 of usage credit every month. Start with a 14-day trial: $50 of credit and a first security audit on us. A card is required.

[Get started](https://dashboard.bugstack.ai/login) [Book 15 minutes with the founder](https://cal.com/mason-bachmann-1atgdq/15min)