{"slug": "mongodb-sandboxes-that-refuse-what-production-refuses", "title": "MongoDB Sandboxes That Refuse What Production Refuses", "summary": "Argon 2.11.0 now builds each collection's secondary indexes in every sandbox, so an insert that production would reject with a duplicate key error fails inside the sandbox instead of only surfacing at merge check, according to Argon Labs' published benchmark report on Argon 2.11.1. Argon 2.10.0 added per-sandbox MongoDB users that are revoked when the sandbox is discarded, closing a gap where the connection string carried the engine's own credentials and could read every database on the deployment. In the test against MongoDB 7.0.45, the sandbox reproduced a unique index on sku, a compound index on status and total, and a 30-day TTL on createdAt, though the TTL index was built without its expiry.", "body_md": "# MongoDB Sandboxes That Refuse What Production Refuses\n\nArgon 2.11 builds a database's secondary indexes in every sandbox, and 2.10 can give each sandbox its own MongoDB user, revoked on discard. A transcript on the published release, what it costs, and the limits.\n\nCurrent capability notes: checkout materializes a physical database; native actor attribution is per branch/run; undo needs complete images and retained history. CLI sandboxes require watch and scheduled sweep. [Read the capability matrix](https://argonlabs.tech/features#capabilities).\n\nA sandbox is only a good place for an AI agent to work if it behaves like the database the change is meant for. Two things decide most of that. Does it refuse the writes production would refuse? And can the agent reach anything outside its sandbox?\n\nUntil recently Argon got both wrong. A sandbox had the source's documents but only the `_id` index, so an insert that production would reject with a duplicate key error went through. The connection string carried the engine's own MongoDB credentials, so code holding it could read every database the engine could. Two releases changed that:\n\n- **Argon 2.10.0** can give each sandbox its own MongoDB user, revoked when the sandbox goes.\n- **Argon 2.11.0** builds each collection's secondary indexes in every sandbox.\n\nThis post runs both on the published release and shows what is refused. It also covers what happens when the data breaks an index, what the indexes cost, and what is still not covered.\n\n## What we ran\n\n- **Argon 2.11.1** , installed from npm as`argonctl` .\n- **MongoDB 7.0.45** as a one-member replica set with access control (`--auth --keyFile` ), in a container. Argon connects as a root user.\n- A source database `shop` with 1,000 orders and three secondary indexes: unique on`sku` , compound on`status, total` , and a 30-day TTL on`createdAt` . A second database,`billing` , stands for everything else on the deployment.\n\nEvery command and its output is in [the transcript](https://github.com/argon-lab/benchmarks/tree/main/reports/2026-11-21-v2.11.1-sandbox-safety/transcript.txt), with passwords masked. [The report](https://github.com/argon-lab/benchmarks/tree/main/reports/2026-11-21-v2.11.1-sandbox-safety) has the script that produced it. Below, `$SANDBOX` is the connection string Argon returned; IDs and long output are shortened with …\n\n## The source's indexes, in the sandbox\n\n``` js\n$ mongosh \"$ENGINE\" --eval 'db.getSiblingDB(\"shop\").orders.getIndexes().map(i => i.name)'\n[ '_id_', 'sku_1', 'status_1_total_-1', 'createdAt_1' ]\n\n$ argon import database --uri \"$ENGINE\" --database shop --project shop --source-quiesced --yes\n$ argon sandbox create -p shop --name agent-run --ttl 1h --credential --output json\n{\n  \"connection_string\": \"mongodb://sandbox_6b015c85…:•••@localhost:27017/argon_br_6b015c85…?authSource=argon_br_6b015c85…&replicaSet=rs0\",\n  \"index_notes\": [\n    \"index createdAt_1 on orders was built without its TTL expiry\"\n  ],\n  \"indexes\": 3,\n  …\n}\n```\n\nThe import recorded the three definitions, and the checkout built them after copying the documents. Inside the sandbox:\n\n``` bash\n$ mongosh \"$SANDBOX\" --eval 'db.orders.getIndexes().map(…)'\n[ '_id_', 'sku_1 unique', 'status_1_total_-1', 'createdAt_1' ]\n\n$ mongosh \"$SANDBOX\" --eval 'db.orders.updateOne({_id: 7}, {$set: {status: \"refunded\"}})'\n{ acknowledged: true, insertedId: null, matchedCount: 1, modifiedCount: 1, upsertedCount: 0 }\n\n$ mongosh \"$SANDBOX\" --eval 'db.orders.insertOne({_id: 5000, sku: \"sku-42\"})'\nE11000 duplicate key error collection: argon_br_6b015c85….orders index: sku_1 dup key: { sku: \"sku-42\" }\n```\n\nThe duplicate `sku` fails where the agent writes it, as it would in production. Before 2.11 the insert succeeded. The conflict surfaced only at `argon merge check`, after the agent's run, or when the write reached the real database. Queries in the sandbox now use the same indexes as on the source too.\n\n`createdAt_1` is there, but without its expiry. A copy of a database is often older than its newest documents' TTL. With the expiry kept, MongoDB would start deleting the sandbox's documents on its own, and capture would record those deletions as the agent's changes.\n\nThe definitions come from three places:\n\n- the import, which reads the source's indexes;\n- following, which records index builds and drops on the source as they happen;\n- capture, which records index builds and drops made through a branch's own checkout. These apply to that branch and its descendants, not to its parent.\n\nIndexes are not versioned: a branch uses the latest definitions recorded for it. Details are in the [operations guide](https://github.com/argon-lab/argon/blob/v2.11.1/docs/OPERATIONS.md#indexes-in-checkouts) and [the pull request](https://github.com/argon-lab/argon/pull/190).\n\n## A MongoDB user for each sandbox\n\n`--credential` made the connection string above carry a user named after the sandbox's branch ID. It can read and write that one database, and that database is its `authSource`. Argon returns the password once and stores only the user name. Outside the sandbox:\n\n``` bash\n$ mongosh \"$SANDBOX\" --eval 'db.getSiblingDB(\"billing\").invoices.findOne()'\nnot authorized on billing to execute command { find: \"invoices\", … }\n\n$ mongosh \"$SANDBOX\" --eval 'db.getSiblingDB(\"argon_br_6b015c85…\").orders.findOne()'   # main's database\nnot authorized on argon_br_6b015c85… to execute command { find: \"orders\", … }\n\n$ mongosh \"$SANDBOX\" --eval 'db.getSiblingDB(\"argon_wal\").wal_log.findOne()'\nnot authorized on argon_wal to execute command { find: \"wal_log\", … }\n```\n\nDiscarding the sandbox drops the user before the database. We kept a connection open across the discard, writing once before and once after:\n\n``` bash\n$ argon sandbox discard -p shop -b agent-run\nDiscarded; storage reclaimed.\n\n# the connection opened before the discard\nfirst write: ok\nsecond write: Command update requires authentication\n\n$ mongosh \"$SANDBOX\" --eval 'db.orders.findOne()'   # a new connection\nMongoServerError: Authentication failed.\n```\n\nThree conditions apply:\n\n- **The deployment must enforce authentication.** On one that does not, a per-sandbox user would not be enforced, so Argon refuses the flag. The REST API answers 422 since 2.11.1.\n- **The engine needs `userAdmin`** on the sandbox databases, or` userAdminAnyDatabase` .\n- **Expiry alone revokes nothing.** An expired sandbox's credential keeps working until a sweep runs. The REST and MCP servers sweep every minute; with the CLI alone, schedule`argon sandbox sweep` .\n\nWithout the flag the connection string still uses the engine's credentials. The Python SDK takes the same option as `create_sandbox(..., credential=True)` from 0.3.0. See [Exposure and credentials](https://github.com/argon-lab/argon/blob/v2.11.1/docs/OPERATIONS.md#exposure-and-credentials) and [the pull request](https://github.com/argon-lab/argon/pull/182).\n\n## When the data breaks an index\n\nAn index can only be built over data that satisfies it. To see what happens otherwise, we made a branch, checked it out with capture running, dropped its unique index and inserted a duplicate. That is the kind of change an agent cleaning up data might make.\n\n``` bash\n$ mongosh \"$CLEANUP\" --eval 'db.orders.dropIndex(\"sku_1\"); db.orders.insertOne({_id: 6000, sku: \"sku-42\"})'\n{ acknowledged: true, insertedId: 6000 }\n\n$ argon merge preview -p shop -b cleanup\nMerging cleanup → main\n  put    orders/~argon:bson:DAAAABBpAHAXAAAA\n1 change(s), 0 conflict(s)\n\n$ argon merge apply 6b015ca0d335a77244e5d98c   # main is checked out and has sku_1\nError: apply failed: write exception: write errors: [E11000 duplicate key error collection: argon_br_6b015c85….orders index: sku_1 dup key: { sku: \"sku-42\" }]\n```\n\n`main` was checked out, so its database still had the unique index, and MongoDB refused the merge. Nothing changed: `main` stayed at LSN 1002.\n\nWith `main` released, nothing enforced the index at merge time. A fresh preview applied, and the next sandbox reported what it could not build:\n\n``` bash\n$ argon release -p shop -b main\n$ argon merge apply 6b015ca0d335a77244e5d98c\nError: apply failed: stale plan: branch state changed since preview; run preview again\n$ argon merge preview -p shop -b cleanup     # saves plan 6b015ca01cdbacf2ac128b6b\n$ argon merge apply 6b015ca01cdbacf2ac128b6b\nMerged: 1 change(s) applied.\n\n$ argon sandbox create -p shop --name next-run --ttl 1h\nSandbox \"next-run\" forked from main at LSN 1008.\nNote: index sku_1 on orders was not built: (DuplicateKey) Index build failed: … E11000 duplicate key error … dup key: { sku: \"sku-42\" }\nNote: index createdAt_1 on orders was built without its TTL expiry\n```\n\nThe checkout built the other indexes and named the one it skipped, in the CLI output and in `index_notes`. It did not fail the whole sandbox.\n\nThe broader point: indexes are not versioned, and a merge does not carry index changes. Keep the branch you merge into checked out if you want MongoDB to enforce its unique indexes at merge time. Run `argon merge check` before writing a plan back to the source.\n\n## What it costs\n\nBuilding indexes takes time, and a checkout now does it before the sandbox is handed over. We ran Argon 2.10.0 and 2.11.1 alternately, three rounds each with three sandboxes per round, at 100,000 documents of about 1 KB:\n\n| Fixture | 2.10.0, ready | 2.11.1, ready | \n|---|---|---|\n| 1 collection, only the `_id` index | 1.98 s (1.67–2.32) | 2.04 s (1.73–2.35) | \n| 10 collections, 20 secondary indexes | 1.70 s (1.61–2.55) | 4.21 s (4.05–4.27) | \n\nMedians of nine sandboxes, with the range in brackets. The first write afterwards took a few milliseconds in both releases.\n\nWithout secondary indexes nothing changed. With 20, a sandbox of this size takes about 2.5 seconds longer. The host is shared and its load average was 11 to 13 throughout, so the absolute times are inflated; alternating the releases keeps the comparison fair. The figures are in [the report](https://github.com/argon-lab/benchmarks/tree/main/reports/2026-11-21-v2.10.0-v2.11.1-index-cost). For how readiness grows with size, see the [earlier measurement](https://github.com/argon-lab/benchmarks/tree/main/reports/2026-11-20-v2.9.0-sandbox-ready): 0.2, 2.4 and 16 seconds at 10,000, 100,000 and 1,000,000 documents, nearly all of it the physical copy.\n\n## Which deployments this is tested on\n\nSince 2.10.0, importing, following and write-back are tested against sources with access control and TLS, using the least-privilege role for each command. They are also tested through primary elections on a three-member replica set, and with MongoDB 6.0 and 8.0 sources and an 8.0 engine ([pull request](https://github.com/argon-lab/argon/pull/185)). The [source permissions](https://github.com/argon-lab/argon/blob/v2.11.1/docs/OPERATIONS.md#source-permissions) table lists the roles. Grant `listIndexes` so that sandboxes get the source's indexes; without it the import still works and says which collections get only `_id`.\n\n## Limits\n\n- Indexes are not versioned. A branch uses its own or its nearest ancestor's latest definitions, and a merge does not carry index changes.\n- Validators, collation defaults and other collection options are not copied.\n- Atlas itself and sharded sources are not tested. Atlas Search indexes are not secondary indexes and are not built.\n- A sandbox credential needs a deployment that enforces authentication. It stays valid after expiry until a sweep runs.\n- Checkout copies the data, so readiness grows with the database. Index builds add to it.\n\nThe full list for this release is in the [changelog](https://github.com/argon-lab/argon/blob/v2.11.1/CHANGELOG.md).\n\n## Try it\n\n```\nnpm install -g argonctl@2.11.1 --allow-scripts=argonctl\nexport MONGODB_URI=\"mongodb://…\"           # a replica set; with access control for --credential\nargon import database --uri \"$MONGODB_URI\" --database shop --project shop --source-quiesced --yes\nargon sandbox create -p shop --ttl 1h --credential --watch\n```\n\nThe sandbox's JSON output, or its notes on stdout, lists the indexes it built. Discard it with `argon sandbox discard -p shop -b <name>`.\n\n## Frequently asked questions\n\n- Does an Argon sandbox have the same indexes as the source database?\n- From Argon 2.11.0, yes for secondary indexes. The import records each collection's index definitions, following and resync keep them current, and every checkout builds them after copying the documents. A unique index therefore refuses a duplicate key inside the sandbox, as it would in production. A TTL index is built without its expiry, and an index the sandbox's data violates is skipped and reported. Validators and collection options are still not copied.\n- Can each sandbox get its own MongoDB user?\n- Yes, from Argon 2.10.0: argon sandbox create --credential returns a connection string for a user that can read and write only that sandbox's database. In our run that user was refused on another database, on the main branch's database and on Argon's metadata. The deployment must enforce authentication, and the engine needs userAdmin on the sandbox databases; otherwise Argon refuses to issue the credential.\n- What happens to the credential when the sandbox is discarded?\n- Argon drops the user before it drops the database. In our run a connection that was already open failed its next write with \"requires authentication\", and a new connection failed to authenticate. An expired sandbox's credential stays valid until a sweep runs; the REST and MCP servers sweep every minute.\n- How much slower is a sandbox with indexes?\n- At 100,000 documents spread over ten collections with 20 secondary indexes, a sandbox was ready in about 4.2 s on Argon 2.11.1 against 1.7 s on 2.10.0, which did not build them. With no secondary indexes the time did not change. Both releases were run alternately on the same shared host.\n- Is this tested on Atlas?\n- No. Since 2.10.0 the import, follow and write-back tests cover access control with least-privilege roles, TLS, primary elections on a three-member replica set, and MongoDB 6.0 and 8.0. Atlas itself and sharded sources are not tested.\n\n## Continue reading\n\n- [Branch a Live MongoDB Database and Write Reviewed Changes Back](https://argonlabs.tech/blog/branch-live-mongodb-write-back)\n- [Connect a Code Sandbox to a MongoDB Sandbox: A Runnable Example with boxd](https://argonlabs.tech/blog/connect-code-sandbox-to-mongodb-sandbox-boxd)\n- [Code Sandboxes Isolate What Agents Run. What Isolates What They Write?](https://argonlabs.tech/blog/code-sandbox-vs-data-sandbox-for-ai-agents)\n\nArgon is open source and MIT-licensed.", "url": "https://wpnews.pro/news/mongodb-sandboxes-that-refuse-what-production-refuses", "canonical_source": "https://argonlabs.tech/blog/mongodb-sandbox-indexes-scoped-credentials", "published_at": "2026-11-21 00:00:00+00:00", "updated_at": "2026-11-21 09:14:35.072928+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-safety"], "entities": ["Argon Labs", "Argon 2.11.0", "Argon 2.10.0", "Argon 2.11.1", "MongoDB 7.0.45", "argonctl"], "also_reported_by": [], "takeaway": "Argon 2.11.0 builds secondary indexes in sandboxes so duplicate-key writes fail there as in production, but TTL indexes are built without their expiry, so agents can still write data production would have aged out.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/mongodb-sandboxes-that-refuse-what-production-refuses", "markdown": "https://wpnews.pro/news/mongodb-sandboxes-that-refuse-what-production-refuses.md", "text": "https://wpnews.pro/news/mongodb-sandboxes-that-refuse-what-production-refuses.txt", "jsonld": "https://wpnews.pro/news/mongodb-sandboxes-that-refuse-what-production-refuses.jsonld"}}