How to Configure Haystack MongoDB Sandbox
You set up a haystack mongodb sandbox by creating an isolated database and assigning a scoped role. Then you connect your pipeline using that specific database user. Teams often start by reusing a broad admin user to get pipelines running fast. Overly broad roles let a rogue pipeline modify data or drop collections by mistake. A safe setup pairs strict database roles with clear limits on what queries can run. How a haystack mongodb sandbox works with native roles A Haystack pipeline uses docu
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 a haystack mongodb sandbox by creating an isolated database and assigning a scoped role. Then you connect your pipeline using that specific database user. Teams often start by reusing a broad admin user to get pipelines running fast. Overly broad roles let a rogue pipeline modify data or drop collections by mistake. A safe setup pairs strict database roles with clear limits on what queries can run.
How a haystack mongodb sandbox works with native roles
A Haystack pipeline uses document stores and retrievers to fetch context for language models. When you connect this pipeline to MongoDB, the database checks the user role first. MongoDB uses role-based rules to grant actions on specific resources. A role applies to its defined database and can scope permissions down to one collection. Note that MongoDB Atlas users have different built-in roles than self-hosted users. Still, both options build from the exact same set of privilege actions.
For a retrieval pipeline, the built-in read role is the safest starting point. The read role allows reading all non-system collections in that specific database. It permits actions like finding documents, listing collections, listing indexes, and viewing collection stats. It also allows opening a change stream to watch for document updates. The read role blocks actions that insert, update, or remove documents. It also stops the pipeline from dropping a collection.
Some pipelines need to index new embeddings or write intermediate agent state. For those workloads, teams assign the readWrite role on a dedicated database. The readWrite role includes every action in the read role plus data changes. It permits inserting, updating, and removing documents inside that database. It also allows creating or dropping collections and indexes. Scoping this role to one test database keeps other databases safe from pipeline writes.
What native roles solve and what they leave open
Native MongoDB roles do a great job of controlling who can log in. They also draw a hard line between read-only pipelines and write-enabled indexing jobs. If a retrieval pipeline only has the read role, it cannot delete your records. If an indexing pipeline is scoped to one collection, it cannot touch other tables.
Still, static roles only check permissions when the session starts and when actions run. They do not inspect the actual contents of individual queries or returned documents. A read role still lets a pipeline pull every single document in a collection. If that collection holds emails, phone numbers, card numbers, or national IDs, the pipeline gets them. The language model then processes those raw fields in its prompt context.
MongoDB Authentication & Authorization + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles also require you to hand database credentials to the app runtime. Every worker node running your Haystack code must hold a valid username and password. Rotating those secrets across many test workers takes manual effort and causes downtime. Finally, collection-level roles cannot require human approval before a high-risk write or drop action runs. Teams need a way to inspect queries in flight and rewrite sensitive fields in results.
Best practices for isolating pipeline test data
Start by separating your retrieval user from your data ingestion user. Give the retrieval pipeline a user with only the read role on the target database. Give the ingestion script a separate user with the readWrite role. Never share one database user across multiple pipelines or developer laptops.
Next, keep your test collections small and free of raw customer records when possible. If you must test against real data structures, mask emails and card numbers in results. Track every query your pipeline sends so you can spot slow or broad scans early. This keeps your test runs fast, safe, and easy to audit.
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
Which MongoDB role should a read-only Haystack retriever use?
Assign the built-in read role on the specific database that holds your documents. This role allows finding records and listing indexes while blocking all inserts, updates, and drops.
Can I restrict a Haystack pipeline to a single MongoDB collection?
Yes, MongoDB roles can grant privilege actions down to the collection level. You can create a custom role that only permits find actions on one specific collection.
What is the difference between read and readWrite roles in a sandbox?
The read role only allows querying data and viewing stats. The readWrite role adds actions to insert, update, or remove documents and create or drop collections and indexes.
Related guides
In this post