Blog/Engineering

Engineering

Sandboxing coding agents: what we isolate, and why

AnjiDevOps Engineer, EnWithAI

3 min read

Talk to us

Five walls around an agent run

  1. WorkspaceA fresh, isolated environment per run
  2. CredentialsShort-lived, scoped to one repository
  3. NetworkDeny by default; allow what builds need
  4. LimitsCPU, memory and time capped
  5. LogsEvery command, kept for review

Assume the agent will try something you did not expect. Make that safe.

A coding agent does not only write code. It runs it: installs packages, executes tests, starts servers. Anything that runs code you have not read needs a sandbox. Here is the one we use, and why each wall is there.

The short answer

Sandbox AI coding agents by running each task in a fresh isolated workspace, giving it short-lived credentials scoped to one repository, denying network access except what builds need, capping resources and time, and logging every command for review.

The threat is mostly accidents

Most agent incidents are not attacks. They are an agent deleting a directory it should not have touched, running a migration against the wrong database, or installing a package with a typo in its name. A good sandbox makes those mistakes cheap. It also limits the damage of the rarer case: a prompt injected through a file or a web page the agent read.

Wall 1: a fresh workspace per run

Each task starts in a clean, isolated environment with only the repository it needs, and it is thrown away afterwards. Nothing carries over between runs: no cached credentials, no leftover files, no state another task left behind.

Wall 2: scoped, short-lived credentials

  • One repository per token. The run can read and push to its branch, and nothing else.
  • Short expiry. Tokens last as long as the run, so a leaked one is useless soon after.
  • No production secrets. Test environments use test data and test credentials. The agent never sees production keys.

Wall 3: controlled egress

Network access is denied by default. We allow the model endpoint, your source control, and the package registries your builds already use, ideally through your own mirror. Every other outbound attempt is blocked and logged, which also tells you when an agent is trying to fetch something it should not.

Most data leaves through the network. Close the network and most risks close with it.

Wall 4: resource and time limits

Agents can loop. Cap CPU, memory, disk and wall-clock time per run, so a stuck test suite or a runaway process ends on its own and costs a few minutes, not a night of compute.

Wall 5: logs a person can read

Every command the agent ran, every file it changed and every network call it attempted goes to a log tied to the task and the spec it was working on. When something looks wrong in review, the reviewer can see exactly what happened, not just the final diff.

The human gate still matters

A sandbox limits what an agent can break while it works. It does not decide whether the work is right. Code still lands as a pull request in your repository, goes through your pipeline, and merges only when a person approves.

In CrewPE

Coding agents build each story to the approved spec, check it against every acceptance criterion, and a person approves the merge. Code ships only through your own release pipeline.

See how CrewPE keeps you in control

Questions teams ask

Why do AI coding agents need a sandbox?
Because they run code: installing packages, executing tests and starting services. A sandbox limits the damage of mistakes, such as deleting files or reaching the wrong system, and of injected instructions from content the agent read.
What should an AI coding agent sandbox include?
A fresh isolated workspace per task, short-lived credentials scoped to one repository, network egress denied by default, resource and time limits, and a log of every command and network call.
Does a sandbox replace code review?
No. It limits what an agent can affect while it works. Whether the change is correct is still decided by acceptance criteria, your pipeline and a person approving the merge.

Anji

DevOps engineer at EnWithAI, building and running CrewPE deployments in customer cloud accounts and on-premises.

Keep reading

Bring one real change. See how it would be specified, built and proven.

Start with a 45-minute call about your system: how it is built, how work is agreed today, and a sensible first step.