How to Configure OpenHands SQL Server Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up openhands sql server credentials, create a dedicated database user with a fixed read role. Then, pass those login details into the agent runtime workspace so it can run queries. Many teams start by giving the agent a broad admin login to save time. This shortcut lets an autonomous agent drop tables or read sensitive records by mistake. How openhands sql server credentials work with native roles SQL Server splits identity between the server level and the database level. A database us

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 openhands sql server credentials, create a dedicated database user with a fixed read role. Then, pass those login details into the agent runtime workspace so it can run queries. Many teams start by giving the agent a broad admin login to save time. This shortcut lets an autonomous agent drop tables or read sensitive records by mistake.

How openhands sql server credentials work with native roles

SQL Server splits identity between the server level and the database level. A database user is the identity of a login when it connects to a database. If your agent needs many databases on one instance, use a login in master. That login maps to a standard SQL user inside each target database.

If the agent only needs one database, you can use a contained database user. This user has a password and is not tied to a login in master. An admin must first turn on contained databases on the server and the database. In total, SQL Server offers thirteen types of database users for different needs.

After you create the user, you assign a role to control what it does. Every database user starts in the public role, which includes permission to connect. Fixed database roles offer a quick way to set broad read or write rules. You cannot change the permissions that belong to these built-in fixed database roles.

For an agent that only inspects schemas or runs reports, use the datareader role. Members of this role can read all data from all user tables and views. If the agent must update rows, the datawriter role lets it change user tables. It can add, delete, or change data across every user table in that database.

Never give an AI coding agent the database owner role for routine tasks. A database owner can run all maintenance tasks and even drop the whole database. You can also pair a read role with a deny role for extra safety. The deny datawriter role stops a user from adding, changing, or deleting any data.

Why static roles leave a gap for AI agents

Native roles do a good job of controlling who can log into the database. They also set clear boundaries between reading tables and writing new rows. Still, fixed roles apply to the whole database rather than single tables or columns.

Ephemeral Credentials + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

A datareader user can still read every user table and view in the database. That includes tables holding emails, phone numbers, card numbers, or national IDs. Native roles cannot rewrite matched fields in query results before the agent reads them.

Storing static passwords inside an agent workspace also creates a major risk for teams. The agent can read its own runtime variables or print them in task logs. Also, native roles only check permissions at login and cannot pause a bad query.

Scoping table permissions for safer agent runs

When fixed roles are too broad, admins should build custom roles with specific grants. Instead of granting read rights to all tables, grant select rights on safe views. You can pair this with the deny datareader role on sensitive user tables. Members of the deny datareader role cannot read data or metadata from user tables. This setup keeps the agent focused on the exact tables it needs to fix code.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev is an open-source proxy that sits next to SQL Server as a sidecar for your SQL Server. It inspects TDS batches and parameterized queries in real time.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused with your message. Matched sensitive fields in supported result columns are masked in memory, and each decision is logged per listener. Check out the code on GitHub.

Frequently asked questions

Should I use a login in master or a contained user for OpenHands?

Use a contained user if the agent only needs one or a few databases. Use a login in master when the agent must reach many databases on one instance. Remember that an admin must enable contained databases on the server and database first.

Can the fixed datareader role hide sensitive columns from an agent?

No, the fixed datareader role lets the user read all user tables and views. You cannot change the permissions assigned to a fixed database role in SQL Server. To block specific tables, create a custom role or grant rights on limited views.

How do I stop OpenHands from changing data in SQL Server?

Assign the agent user to the fixed datareader role and the deny datawriter role. The deny datawriter role ensures the user cannot add, change, or delete any data. Also make sure the user is never added to the database owner role.

The query runs. The emails stay hidden.