How to Configure OpenHands SQL Server Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up an openhands sql server prevent delete workflow, restrict the agent database user. You must grant read and write rights while blocking row removal on user tables. AI coding agents run SQL queries to test apps, fix bugs, and check data. Many teams give these agents a broad login to speed up early setup. When a role is too broad, one bad prompt can wipe out production rows. You need clear database rules before an autonomous agent runs queries on live tables. How openhands sql server pr

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.

To set up an openhands sql server prevent delete workflow, restrict the agent database user. You must grant read and write rights while blocking row removal on user tables. AI coding agents run SQL queries to test apps, fix bugs, and check data. Many teams give these agents a broad login to speed up early setup. When a role is too broad, one bad prompt can wipe out production rows. You need clear database rules before an autonomous agent runs queries on live tables.

How openhands sql server prevent delete roles work

In SQL Server, a database user is the identity of a login inside a database. When an agent needs many databases on an instance, teams create a login in master. For one or a few databases, teams can use a contained database user with a password. An admin must first turn on contained databases on the server and the database itself. SQL Server supports thirteen types of database users to match different identity needs.

After you create the user, you must assign permissions to control table changes. Many admins start with fixed database roles, which all include the basic connect permission. Still, you cannot change the permissions assigned to fixed database roles in SQL Server. For example, the fixed data writer role lets members add, delete, or change data everywhere. If you add the agent to the deny data writer role, it blocks all changes. That role stops the agent from adding, changing, or deleting rows in any table. Worst of all, the database owner role can perform all maintenance and drop the database.

Because fixed roles group inserts, updates, and deletes together, you need custom permissions instead. You can place the agent in the fixed data reader role to read all tables. Then you grant insert and update rights on specific tables or schemas to that user. You can also apply an explicit deny rule for delete actions on those user tables. In SQL Server, an explicit deny overrides a grant from another custom role. This setup lets OpenHands read data and write new records while blocking delete statements.

Where native database roles fall short for AI agents

Native roles and table grants solve the basic problem of who can log in. They also set static rules on which tables a database user can touch. Still, static database permissions do not inspect what individual statements do in flight. An agent with update rights can still overwrite every row in a table by mistake. A bad update query with no filter clause can set every email to null.

SQL Injection Prevention + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static roles also do not rewrite sensitive fields in query results before the agent reads them. If the agent belongs to the fixed data reader role, it reads all user tables. That means customer emails, phone numbers, card numbers, and national IDs flow into agent logs. Also, managing table grants across dozens of databases takes constant manual work. When schemas change, admins must update permissions for the agent user on every new table. Teams need a way to check queries in flight and mask sensitive fields in results.

Check SQL Server batches and results on the wire

SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server. It reads plain batches and parameterized queries on the TDS wire while passing Windows login through untouched.

Before a batch hits the server, hoop.dev guardrails check the statement against your rules. Disallowed actions get a native TDS error with your message. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns that match your rules. Every query and decision is logged. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can I use the fixed data writer role and still block deletes?

Yes, you can apply an explicit deny for delete permissions on the target tables. Still, granting only read, insert, and update permissions is cleaner and safer to maintain.

Why should OpenHands never use the database owner role?

Members of the database owner role can run all maintenance tasks and drop the database. An autonomous agent should never hold permissions that can destroy the entire database.

Does blocking delete statements protect against all data loss?

No, an agent with update permissions can still overwrite valid data with blank values. You also need controls to review risky update queries before they run on production tables.

The query runs. The emails stay hidden.