How to Configure OpenHands SQL Server Least Privilege
You set up openhands sql server least privilege by creating a dedicated database user. Then you grant that user only the table or role permissions needed to work. Teams often start by giving an AI coding agent a broad shared login. That shortcut creates real risk during automated debugging and code test runs. If an agent holds full owner rights, one bad query can drop tables. It can also delete rows or pull customer data into agent logs. Scoping the database identity down to minimal read or writ
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 openhands sql server least privilege by creating a dedicated database user. Then you grant that user only the table or role permissions needed to work. Teams often start by giving an AI coding agent a broad shared login. That shortcut creates real risk during automated debugging and code test runs. If an agent holds full owner rights, one bad query can drop tables. It can also delete rows or pull customer data into agent logs. Scoping the database identity down to minimal read or write permissions stops that damage.
How openhands sql server least privilege works in practice
SQL Server separates server logins from individual database users. A login lives in the master database and lets someone enter the server. A database user is the identity of that login inside one specific database. When an agent needs many databases on one instance, teams create a login first. Then they map a database user to that login in each target database.
When an agent only needs one database, a contained database user works well. A contained user has its own password and does not need a master login. An admin must turn on contained databases on the server and database first. SQL Server supports thirteen types of database users for different identity setups.
After creating the user, you assign permissions using roles or direct table grants. Every database user starts in the public role, which includes basic connect rights. Fixed database roles offer a fast way to group standard permissions. For example, the datareader role lets a user read all user tables and views. The datawriter role lets a user add, change, or delete data across user tables. You cannot change the permissions built into these fixed database roles.
Never assign the database owner role to an automated coding agent. Members of that owner role can run all maintenance tasks and drop the database. You can also combine roles with explicit deny roles to lock down sensitive areas. The deny datawriter role blocks all data changes across every user table. The deny datareader role blocks reading any user tables, views, or their metadata. For tighter control, skip fixed roles and grant select rights on specific tables only.
Where native database roles fall short for AI agents
Native SQL Server roles decide who can log in and which objects they touch. They do not inspect what individual queries do while a session is active. A read-only agent with the datareader role can still read every user table. If a table holds emails, phone numbers, card numbers, or national IDs, queries return them. The agent then reads those raw values and stores them in its task context.
Least Privilege Principle + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static roles also stay active around the clock once you set them up. You have to hand out a password and store it in the agent workspace. If the agent needs a quick schema fix, someone must alter its role manually. Until an admin removes that write role, the agent keeps broad change rights. Native database grants cannot pause a single risky delete statement for human review.
Scoping agent access down to specific schemas and views
You can narrow native access further by grouping safe tables into a custom schema. Instead of the fixed datareader role, grant read rights only on that one schema. You can also build views that leave out sensitive columns from underlying tables. Grant the agent user select rights on those safe views only. Leave the base tables off limits so the agent only queries approved columns. This approach shrinks what the agent can touch using native SQL Server rules. Even so, managing custom views for every agent task takes ongoing admin work.
Add runtime guardrails beside SQL Server
Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev runs beside the database as a sidecar for your SQL Server and checks TDS traffic without changing how clients log in.
With hoop.dev SQL Server controls, rules refuse banned statements before they run and can hold risky queries for human review. Matched sensitive values in supported result columns are masked before they reach the client. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.
Frequently asked questions
Should I use a SQL login or a contained user for OpenHands?
Use a contained database user if the agent only needs one database. It keeps the user and password inside that single database without a master login. Use a standard SQL login if the agent must query many databases at once.
Why is the fixed datareader role sometimes too broad for an AI agent?
Members of the fixed datareader role can read all user tables and views. You cannot change the permissions inside a fixed role to hide specific tables. If your database holds private columns, grant select on safe tables or views instead.
How can I block an OpenHands user from changing data by mistake?
Do not add the agent user to the datawriter or owner roles. You can also add the user to the deny datawriter role as a safeguard. That role stops the user from adding, changing, or deleting rows in user tables.
Related guides
In this post