---
title: "Sandboxes for background agents: full dev environments that pause when idle"
description: "Promigence gives background agents a full development environment forked from a verified snapshot, can pause it while the agent waits on a person, a queue or a timer, and never bills paused time."
url: "https://www.promigence.ai/for/background-agents"
site: "Promigence"
---

# Background agents with a full dev environment, and no bill while they wait

Promigence gives background agents a full development environment forked from a verified snapshot: your repository, its services and its build, ready when the agent starts. A long-running agent can pause while it waits on a person, a queue or a timer, and paused time is not billed.

**Who this is for:** Platform teams building internal background agents, and teams running vendor coding agents on their own pool.

## What breaks today
### A real task needs the whole dev environment
Databases, queues and a built frontend, not just a repository. Setting that up for every task takes longer than the task.

### Agents spend most of their time waiting
On a reviewer, a queue or a timer. A sandbox billed for every second of that wait costs more than the work it does.

### Secrets and network access need a boundary
An agent with production-like access must reach the hosts it should and nothing else, with credentials that are not baked into the environment.

## What changes with Promigence
### One snapshot of the full environment
Set up the services and the build once, verify them, and fork the finished environment for each agent run.

### Pause while the agent waits
Set an idle rule and a sandbox pauses itself when nothing is happening, then wakes on the next request. Paused time is not billed.

### Allow-listed network and secrets at run time
An outbound allow-list, with every refused host recorded, and secrets injected at run time, never stored in the snapshot your build produces.

## A dev environment that pauses itself when idle
```bash
# Store a credential once; it is injected at run time, never stored in the snapshot your build produces
promigence secrets set GITHUB_TOKEN --from-env GITHUB_TOKEN

# Fork the environment and let it pause itself when idle
promigence fork --snapshot devenv@9b0d3f1 --count 1 --cap 1
promigence sandbox autopause "$SANDBOX" --after 30s

# What it may reach, and every host it was refused
promigence sandbox network "$SANDBOX"
```

## What infrastructure should you use to run background coding agents on your private repos?

Give each task its own isolated sandbox that opens on your private repository with the dependencies installed and the tests passing, holds the model key as a stored secret, and reaches only the hosts the work needs. While the agent waits on a reviewer or a queue, the sandbox should pause and stop billing. On Promigence that means a verified snapshot of the repository, an outbound allow-list, an idle rule, and a spend cap on every sandbox.

## How it works

### Connect the repository and build it once

Connect GitHub once with `promigence github connect`. Then build a snapshot of the repository whose setup steps install everything the task touches, including the services it talks to, and whose verify command must pass before anything is stored. A `--start` command brings up any service that should already be running when the agent arrives. The Claude Code guide has the private-repository version of the build command.

### Start the agent with its key stored

The first line reads the model key from your environment; the second stores it as a secret and starts Claude Code in a new sandbox, capped at $2. After the first run, the stored secret is enough. For private code, start it from your snapshot's alias and give it a prompt: the agent then works through the task headless, in the background.

```bash
export ANTHROPIC_API_KEY=...        # already set in most setups
promigence agent start claude --key-from-env ANTHROPIC_API_KEY --cap 2
```

### Name the hosts it may reach

List each host the task needs and nothing more. Sandboxes you start with `promigence fork` take one `--allow` per host, as below, and `promigence sandbox network` then lists the allowed hosts and each one the sandbox was refused. If an agent misbehaves, `--cut` switches its outbound access off at once, for good.

```bash
promigence fork --snapshot my-analysis-env --count 1 --cap 1 \
  --allow pypi.org --allow files.pythonhosted.org
```

### Pause while it waits, then collect the work

Under an idle rule, a quiet sandbox pauses itself and the next request brings it back; paused time is not billed. `promigence sandbox info` reports where it stands: state, time left, cost so far and the commands it ran. When the agent is finished, copy its files out with `promigence files get` and end the sandbox.

## What you get, in numbers

| What | Result | Conditions |
|---|---|---|
| Wake a paused sandbox | 104 ms | From resume to the first database query; median of 100 runs, 127 ms under load [Source](https://www.promigence.ai/#numbers) |
| Time a paused sandbox is kept | 30 days | Waking it starts the 30 days again [Source](https://www.promigence.ai/docs/limits) |
| Whole coding-agent task | 43.7 s | 20 steps on a 3 GB repository; median of 30 runs, 58.0 s under load [Source](https://www.promigence.ai/#numbers) |

## What it costs

Take a task with 30 minutes of real work spread over an afternoon: 20 minutes, a three-hour wait for a person to approve the plan, then 10 minutes more. It runs in a medium sandbox (4 vCPU, 16 GiB) with an idle rule and a $1 cap.

Working time: 1,800 s × $0.000128 = $0.23. Waiting time, paused: $0. Without the idle rule, the sandbox would stay up for 12,600 s: 12,600 × $0.000128 = $1.61.

Total: $0.23 for the task with the idle rule, $1.61 without it.

With a 45-minute timeout, the quote is 2,700 s × $0.000128 = $0.35, inside the $1 cap; paused time does not use up the timeout. A start quoted over its cap is refused, and a sandbox that hits the cap stops billing and keeps its files and state until you raise the cap or end it.

## Security and limits

- Runs can sit behind an outbound allow-list, or have no network at all.
- Unless you force it, no secret is written into a snapshot, because one baked in would reach every sandbox started from that snapshot.
- A paused sandbox costs nothing by the second and takes no place under your concurrency limit.

## Related

- [Run Claude Code, Codex or OpenCode in a sandbox](https://www.promigence.ai/docs/guides/claude-code-and-codex)
- [Run LLM-generated code safely](https://www.promigence.ai/docs/guides/run-ai-written-code-safely)
- [Limits and notices](https://www.promigence.ai/docs/limits)
- [Quickstart](https://www.promigence.ai/docs/quickstart)

## Questions

### What does a background agent cost while it waits?

Nothing by the second, once its sandbox is paused. A paused sandbox is kept for 30 days, and waking it starts the 30 days again.

### How does the sandbox know the agent is waiting?

Through an idle rule you set with `promigence sandbox autopause`. By default, idle means no API requests; with `--mode activity` it also means no CPU use, no network traffic and no open connection inside the sandbox. After the idle time you set, the sandbox pauses itself, and the next request wakes it.

### Can a background agent reach your production systems?

Only the hosts you allow. Give its sandbox an outbound allow-list, or no network at all, and every refused connection is recorded, so you can read what the agent tried to reach.

### Does the model key end up in the environment you build?

No. Secrets reach the sandbox when it runs and stay out of the snapshots you build, and a snapshot of a sandbox that holds one is refused unless you force it.

### How long can a background agent run?

Until its timeout, which you set when it starts: an hour by default for `promigence agent start`. Paused time does not use the timeout up, and `promigence sandbox extend` gives a live sandbox a longer one if the extra time fits under its spend cap. The longest a sandbox may run is one of your account's limits.

### Which agents can work in the background this way?

`promigence agent start` runs Claude Code, Codex or OpenCode headless from a prompt, each in a sandbox of its own. Agents you wrote yourself use the same sandboxes through the SDKs or the CLI.

### What happens if the environment breaks halfway through a long task?

It is recorded as the environment's failure, never the agent's. A sandbox that fails on our side before it reaches you is not billed; after that, when our side shows the failure was ours, the work since its last snapshot or start, up to 24 hours, is credited back.

