How to Configure OpenHands SQL Server Sandbox
You set up an openhands sql server sandbox by isolating the agent container. You then link it to a restricted database user with fixed read-only roles. Teams often start by giving AI coding agents shared admin credentials for testing. Broad roles allow an autonomous agent to drop tables or read sensitive rows. A safer setup pairs container isolation with strict database permissions. How an openhands sql server sandbox works with native roles OpenHands runs tasks inside an isolated container w
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 an openhands sql server sandbox by isolating the agent container. You then link it to a restricted database user with fixed read-only roles. Teams often start by giving AI coding agents shared admin credentials for testing. Broad roles allow an autonomous agent to drop tables or read sensitive rows. A safer setup pairs container isolation with strict database permissions.
How an openhands sql server sandbox works with native roles
OpenHands runs tasks inside an isolated container workspace. When the agent needs database access, it uses credentials stored in that workspace. On the database side, a user represents the identity of a login. Teams that use many databases often create a login in the master database. For one database, a contained database user with a password is an option. An admin must first enable contained databases on the server and the database. Microsoft supports thirteen types of database users for different needs.
Once the user exists, you assign a fixed database role. All roles, including the public role, have basic permission to connect. The permissions inside fixed database roles cannot be changed. Adding the agent user to the data reader role lets it read all user tables. It can also read all views in that database. Adding the data writer role lets the agent add, change, or delete table data. You should avoid the database owner role for an agent workspace. That role can change settings, run maintenance, and drop the whole database.
What native roles solve and what they leave open
Native roles control who can log in and which broad actions they can take. You can combine allow and deny roles to tighten your setup. For example, the deny data writer role stops the user from changing any data. The deny data reader role blocks reading from all user tables and views. It also blocks reading metadata about those objects. These fixed roles are easy to set up and manage across test databases.
Still, native setup rules only check the user identity at login time. They do not inspect what individual queries do while they run in flight. A user in the data reader role can still read every user table. If your test database holds real emails or phone numbers, the agent gets them. A single bad query from the agent can also pull millions of rows at once. Static passwords stored in the agent workspace can also leak into logs. Native roles cannot rewrite sensitive fields like card numbers or national IDs in results. They also cannot pause a risky statement for human review before it runs.
Kubernetes API Server Access + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Steps to harden your agent database workspace
Start by scoping the agent to a single test database with synthetic data. Use a contained database user so the account cannot reach other databases on the server. Assign only the data reader role when the agent only needs to inspect schemas. Add the deny data writer role to make sure no table data changes by mistake. Rotate the user password after each major coding run to limit exposure. Review database query logs often to see what statements the agent sends.
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 give an OpenHands agent the database owner role in a sandbox?
No, because the database owner role can run all maintenance tasks and drop the database. Use narrower roles like the data reader role so the agent cannot destroy your test setup.
What is the difference between a standard login and a contained database user?
A standard SQL user links to a server login stored in the master database. A contained database user has its own password inside one database and needs no master login.
Can native read-only roles hide sensitive columns from an AI agent?
No, the fixed data reader role grants read access to all user tables and views. To hide specific fields like emails or card numbers, you need a tool that rewrites results.
Related guides
In this post