How to Configure OpenHands MongoDB Sandbox
You set up an openhands mongodb sandbox by giving the agent a restricted database user. Then you isolate the runtime container from your production network. Teams often build this setup so coding agents can test queries and fix app bugs. Still, many engineers take a shortcut and hand the agent a broad admin password. When roles are too broad, one bad agent command can wipe out whole collections. A good sandbox pairs container isolation with strict database roles. Setting up an openhands mongod
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up an openhands mongodb sandbox by giving the agent a restricted database user. Then you isolate the runtime container from your production network. Teams often build this setup so coding agents can test queries and fix app bugs. Still, many engineers take a shortcut and hand the agent a broad admin password. When roles are too broad, one bad agent command can wipe out whole collections. A good sandbox pairs container isolation with strict database roles.
Setting up an openhands mongodb sandbox with native roles
OpenHands runs tasks inside an isolated container where the agent writes and runs code. When the agent needs data, it connects to your MongoDB test instance over the network. You control what the agent can do by assigning native MongoDB roles to its user.
MongoDB manages access through role-based rules that grant specific actions on defined resources. A role applies to its target database and can limit access down to one collection. Note that MongoDB Atlas users have different built-in roles than self-hosted database users. Still, both setups build their roles from the exact same set of privilege actions.
For a safe starting point, assign the built-in read role to the agent user. The read role lets the agent query non-system collections and the system JavaScript collection. It allows actions like finding documents, listing collections, listing indexes, and checking database or collection stats. It also allows opening a change stream to watch data updates. The read role blocks the agent from inserting, updating, or removing any documents. It also stops the agent from dropping a collection.
Sometimes your coding agent must test data writes or build new schema indexes. In that case, teams step up to the built-in readWrite role on a test database. This role includes every action in the read role plus the power to change data. The agent can now insert, update, and remove documents during its test runs. It can also create collections, build indexes, drop indexes, and drop collections.
What native roles solve and what they leave open
Native roles and isolated containers solve your basic access problems right away. The container keeps the agent from touching files on your host machine. Meanwhile, the database role decides if the agent can only read or also write data. By scoping a role to a single collection, you keep other collections safe.
Still, native database roles only check who logs in and which broad actions they hold. They do not inspect what individual statements or commands do while in flight. If an agent holds the readWrite role to test inserts, it can also drop collections. Native roles cannot let an agent insert test rows while blocking collection drops in that role.
MongoDB Authentication & Authorization + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Read-only roles leave a big gap when test databases hold real user data. If a collection has real records, the find action returns every field in matching documents. Sensitive fields like emails, phone numbers, card numbers, and national IDs flow straight to the agent. The agent then sends those raw values to the outside language model provider. Also, storing static database keys inside the agent container creates a key leak risk. Because the agent can run shell commands, it can read its own local variables.
Scoping test data and network rules for agents
Before you start the agent, review the data sitting inside your sandbox collections. Replace real emails, phone numbers, and card numbers with fake test values where possible. If you must use real data shapes, set up field masking to rewrite matched fields in results.
Next, lock down the network path between the agent container and your database cluster. Allow traffic only from the specific container network to the test database port. Block the container from reaching production databases or internal services on your private network. Finally, rotate the database password after each major coding run to limit exposure.
Check MongoDB commands and documents on the wire
MongoDB roles and SCRAM login decide who opens a session. They do not check single commands or redact sensitive fields inside returned documents. With hoop.dev, you run an open-source proxy, a sidecar for your MongoDB. It reads the MongoDB wire protocol and checks commands and bulk writes as JSON while passing login through untouched.
Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents that match your rules. Every command and verdict is logged. See the open-source code on GitHub.
Frequently asked questions
What MongoDB role should an OpenHands agent use for bug checks?
Assign the built-in read role scoped to the single database or collection under test. This lets the agent find documents and check indexes while blocking all data changes.
Can the readWrite role stop an agent from dropping a test collection?
No, the built-in readWrite role includes the dropCollection and dropIndex actions by default. To block drops while allowing writes, you must build a custom role or filter commands in flight.
Why is real user data risky inside an agent database sandbox?
When an agent runs a find query, the database returns full documents into the container. Any emails, phone numbers, or card numbers in those results get sent into the model prompt.
Related guides
In this post