
# Mirror vs production

A mirror is your copy of the app for one task: your code running locally on a masked branch of production's database. Start it with `agc up --detach` and break it freely; real users never see it. Only `agc ship` changes production, the live app (exit 0, `"outcome": "live"`).

## Ask your agent

```text
Start a mirror of my app and show me the change running on localhost before you ship anything.
```

The agent runs `agc up --detach` and gives you a `localhost` URL. You see production-shaped data with names and emails replaced.

## How it works

```mermaid
flowchart LR
  subgraph Laptop["Your machine"]
    M["Mirror: dev command, sandboxed<br/>masked DB branch, captured email"]
  end
  subgraph AC["Agent Cloud"]
    R["Rehearsal: fresh unmasked fork<br/>(platform-internal)"]
    P["Production: built image<br/>real data, real email"]
  end
  M -- "agc ship (snapshot)" --> R
  R -- "checks pass, person approves if needed" --> P
  P -. "masked branch" .-> M
```

Changes flow one way: from the mirror through a rehearsal to production. Data flows back to the mirror only as a masked branch.

| | Mirror (yours) | Production |
|---|---|---|
| What it is | A copy of production for your task; it outlives your ships | The live app |
| How the app runs | Natively: your `dev` command on this machine, with its OS, runtime and paths | The image built from your snapshot; a release switches to it only once it answers healthy |
| Data | Masked branch of production (numbers, dates and IDs kept); break it freely | Real; read-only for you, and only through a masked view (`agc db query --env prod`) |
| Shell | `agc exec -- <cmd>`, `agc db` | None |
| Platform email | Captured, not sent (`agc outbox`) | Sent |
| Other outbound calls | Inside the OS sandbox, through agc's proxy, to Agent Cloud, granted connections and `[mirror] egress_allow` hosts only | On Agent Cloud, any public host; on an organization's own target, only hosts an owner approved (`[production] egress_allow`) |
| App secrets | Production values never arrive; your own gitignored `.env.mirror` supplies test keys | Production values as environment variables; nobody can read them back |
| How changes land | Directly, as you save | Only through `agc ship` |

The difference that bites most often is the runtime. A mirror runs your `dev` script on your laptop's Node or Python, while production runs the image Agent Cloud built. So an app can work on the mirror and still fail to start in production, from a missing dependency or a hard-coded port. You find out before users do: traffic switches only once the new image answers healthy, and a ship that rehearses runs that image on a fork first.

**Outbound traffic.** On a laptop, the app, the worker and `agc exec` run inside `sandbox-exec` (macOS) or bubblewrap (Linux, WSL2 and Devboxes). Their only way out is agc's proxy, which forwards to Agent Cloud and the hosts you list:

```toml
[mirror]
egress_allow = ["api.example.com:443"]
```

Private networks and cloud metadata addresses are always refused. `agc status` lists recent refusals by host and port. Where neither sandbox exists, `agc up` refuses with `mirror.isolation_unavailable`. Use test credentials for anything the mirror is allowed to reach.

**The shell environment.** From the shell that launched agc, the mirror gets only basics such as `PATH`, `HOME` and the locale, and `agc up` names what it held back. Put anything else the app needs in `.env.mirror`, which `agc init` gitignores and snapshots never include.

**Private targets.** For an app on an organization's own AWS target, the mirror starts empty: migrations, then the app's seed data. `agc up --at` answers `target.private_data`, and so does `agc db query --env prod` unless an organization owner has turned on production reads (then only Builder and Read-only agents may read). See [Data on private targets](/docs/data/reading-production-safely.md#data-on-private-targets).

**Lifecycle.** A mirror is named after your git branch (or `dev` outside git), so parallel agents in separate worktrees get separate mirrors. It survives ships, so expand, migrate and contract can follow from the same mirror. `[mirror] expire_idle` (default `"3d"`) records a planned expiry on the mirror's database branch, but idle deletion is not implemented, so remove a mirror you're done with using `agc down --delete`.

## Reference

| Key | Where | Meaning |
|---|---|---|
| `egress_allow` | `[mirror]` | `"host:port"` entries the mirror may reach; a wildcard like `"*.example.com:443"` works and warns |
| `expire_idle` | `[mirror]` | Planned expiry recorded on the mirror's database branch, in days, like `"3d"` (default; 1 to 30) |
| `.env.mirror` | app folder | Test values loaded into the mirror, hidden from its log, never shipped |

## Errors

| `code` | exit | Cause | Fix |
|---|---|---|---|
| `mirror.isolation_unavailable` | 1 | Neither `sandbox-exec` nor bubblewrap is available | Install bubblewrap, or let `agc ship` rehearse instead |
| `mirror.db_unreachable` | 1 | This machine can't open a connection to the mirror's database on port 5432 | Run `agc up` where outbound connections to 5432 are allowed, or let `agc ship` rehearse the release |
| `target.private_data` | 12 | The app runs on a customer's private target | Work on the mirror's seed data |

## Agent notes

- A passing `agc check` on the mirror doesn't mean production will start: the image is different. Ship and read the outcome.
- Never ask the person to paste a secret value. Test keys go in `.env.mirror`, which the person maintains.
- Don't paste rows from the mirror into chat or commits, even masked ones. Counts are fine.

## Related

- [Local development with agc up](/docs/build/local-development-with-agc-up.md)
- [Rehearsals](/docs/concepts/rehearsals.md)
- [Masking](/docs/concepts/masking.md)
- [The mirror sandbox and egress](/docs/build/the-mirror-sandbox-and-egress.md)
- [Reading production safely](/docs/data/reading-production-safely.md)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "concepts/mirror-vs-production: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
