Openhands Delete MongoDB
Yes, an openhands delete mongodb event can happen when an AI agent holds write permissions. You can stop this by using strict database roles and approval steps for risky commands. AI coding agents run shell scripts and database queries on their own. When an agent connects to a database, it uses the exact privileges of its login key. If that key allows data removal, a bad prompt or logic loop can wipe out records. How openhands delete mongodb actions happen in practice OpenHands is an autonom
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.
Yes, an openhands delete mongodb event can happen when an AI agent holds write permissions. You can stop this by using strict database roles and approval steps for risky commands.
AI coding agents run shell scripts and database queries on their own. When an agent connects to a database, it uses the exact privileges of its login key. If that key allows data removal, a bad prompt or logic loop can wipe out records.
How openhands delete mongodb actions happen in practice
OpenHands is an autonomous agent that writes code and runs terminal commands. Engineers use it to fix bugs, build features, and check data in development and production.
To work with data, the agent needs a database login. MongoDB uses roles to control what a user or agent can do. A role grants specific actions on a database down to the collection level.
Many teams give their agent the built-in read and write role for convenience. In MongoDB, the readWrite role includes all read privileges plus actions that change data. Specifically, this role permits insert, update, remove, and dropCollection actions on non-system collections.
When the agent has this role, an openhands delete mongodb incident is one bad command away. The agent might try to clean up test data and remove a real collection by mistake. Because the database sees a valid role, it runs the delete command right away.
Security tradeoffs of static roles and active sessions
The simplest fix is to switch the agent to the built-in read role. In MongoDB, the read role grants find, listCollections, listIndexes, dbStats, collStats, and changeStream actions. It does not include insert, update, remove, or dropCollection actions.
Using the read role stops an agent from deleting records or dropping collections. Still, static roles create new problems for daily engineering work. Sometimes an agent needs to insert a test record or update a single document.
MongoDB Authentication & Authorization: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
If you only use a read role, the agent hits a wall and stops working. If you switch back to a write role, you expose every collection in that database again. Static credentials also stay on disk inside the agent workspace, where prompts might leak them.
A static role also cannot check the context of a single query during an active session. It cannot allow a safe update while blocking a full collection drop. Also, read roles still return raw emails, phone numbers, card numbers, and national IDs.
How to control agent queries and mask data
To get safe automation, teams need controls that sit between the agent and the database. First, remove static database keys from the agent workspace so the agent cannot copy them.
Second, inspect queries in real time before they reach the database server. When an agent tries to run a delete or drop action, pause the request. Route that single command to a human engineer for approval before it runs.
Third, apply data masking to query results before they return to the agent. Masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in results. This keeps sensitive user records out of AI prompts and logs while keeping schemas intact.
Inspect MongoDB wire traffic in flight
Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.
Frequently asked questions
Can the MongoDB read role stop an agent from dropping a collection?
Yes, the built-in read role blocks collection drops. It only grants read actions like find and listCollections, and excludes remove and dropCollection actions.
Why do AI agents delete database records by mistake?
Agents often misread instructions or try to reset state during a test run. If their database login has write privileges, the database accepts the delete command.
How can I let an agent write data without risking a full wipe?
Scope the role to specific collections and add an approval step for destructive commands. This lets safe inserts pass while pausing remove or drop actions for human review.
Related guides
In this post