Openhands SQL Server
An openhands sql server setup lets an AI agent run database queries for your team. It uses standard database logins and roles to read schemas, check data, and test fixes. Engineering teams use this setup to speed up daily database work and bug checks. The agent acts like a human user inside its own workspace. It opens a link to the database, sends queries, and reads the output. You must set strict rules so the agent stays safe during each run. How an openhands sql server workflow works in pra
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.
An openhands sql server setup lets an AI agent run database queries for your team. It uses standard database logins and roles to read schemas, check data, and test fixes.
Engineering teams use this setup to speed up daily database work and bug checks. The agent acts like a human user inside its own workspace. It opens a link to the database, sends queries, and reads the output. You must set strict rules so the agent stays safe during each run.
How an openhands sql server workflow works in practice
In an openhands sql server setup, the agent needs a valid database user to log in. A database user is the identity of a login when it connects to a database. Microsoft supports 13 types of database users for different access needs. When an agent needs access to many databases, teams use a SQL user with a login. That main login lives in the master database on the instance.
Sometimes an agent only needs access to one or a few databases. In that case, a contained database user with a password is a good option. This user is not tied to a login in the master database. An admin must first turn on contained databases on the server and the database. Once logged in, the agent runs scripts or tools to inspect tables and views.
Security tradeoffs with static keys and fixed database roles
Database admins often use fixed database roles to limit what an agent can do. Every role, including the public role, has basic connect rights. You cannot change the permissions assigned to fixed database roles. If you give the agent the owner role, it can run all maintenance tasks. That owner role can even drop the whole database in SQL Server.
Most teams prefer a read-only role for AI agents to prevent bad writes. The data reader role can read all data from all user tables and views. The data writer role can add, delete, or change data in all user tables. Admins also use deny roles to block read or write actions across user tables. Even with a read-only role, static passwords in agent files still carry high risk.
Kubernetes API Server Access + SQL Query Filtering: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
A read-only role also lets the agent read every row in every user table by default. Those tables often hold private emails, phone numbers, card numbers, and national IDs. Database roles work at the table level, not at the live query result level. When the agent runs a broad select query, raw data flows into the model prompt. Static roles also cannot pause a risky command to ask a human for approval.
How to control queries and mask sensitive fields in flight
Safe agent access requires controls that sit between the agent and the database. First, remove static database passwords from the agent workspace. Let the agent connect through a central layer that handles database logins for each session. This stops secret leaks if someone reads the agent logs or workspace files.
Second, inspect every query and result set while the session is active. Data masking rewrites matched fields in results before the agent gets the output. This replaces emails, phone numbers, card numbers, and national IDs with safe masks. You can also add approval rules for write queries and log every command.
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, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
How do you limit an AI agent to read-only access in SQL Server?
Assign the agent user to the fixed data reader role in your target database. This role lets the user read all user tables and views without write rights. You can also add the deny data writer role to block any data changes.
Should an agent use a master login or a contained database user?
Use a contained database user when the agent only needs one or a few databases. This keeps the user inside that database and avoids a login in master. An admin must enable contained databases on the server and database first.
Why is a read-only database role not enough for AI agents?
The data reader role still reads all data from every user table and view. This exposes raw emails, phone numbers, and card numbers to the agent prompt. You need field masking in flight to rewrite those values in query results.
Related guides
In this post