How to Configure AutoGen SQL Server Sandbox
To set up an autogen sql server sandbox, create a restricted database user. Then assign that user to a read-only role and limit what the agent runs. Engineering teams often give AI agents shared accounts with broad write rights. This mistake lets a bad prompt alter records or drop tables by accident. Setting up an autogen sql server sandbox with native roles Your first step happens inside the database server itself. In SQL Server, a database user represents the identity of a login upon entry.
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 autogen sql server sandbox, create a restricted database user. Then assign that user to a read-only role and limit what the agent runs. Engineering teams often give AI agents shared accounts with broad write rights. This mistake lets a bad prompt alter records or drop tables by accident.
Setting up an autogen sql server sandbox with native roles
Your first step happens inside the database server itself. In SQL Server, a database user represents the identity of a login upon entry. If the agent needs many databases on one instance, use a login in master. You then map a standard SQL user to that login.
Often, an agent only needs one or two test databases. Here, a contained database user with a password works well. It does not tie back to a login in the master database. An admin must first turn on contained databases on the server and target database. Note that SQL Server supports thirteen total types of database users.
After you make the user, you must assign its permissions. Every role, including the default public role, holds basic connection rights. To keep the agent from changing data, use the built-in fixed database roles. Adding the user to the datareader role lets it read all user tables. It can also read all views inside that database.
You can also add the denydatawriter role to block all data changes. Members of this role cannot add, change, or delete any table data. Never assign the agent to the database owner role. That owner role allows all maintenance tasks and can even drop the database. Remember that you cannot change the permissions built into fixed database roles.
Why native roles fall short for AI agents
Native roles control who can log in to the database. They also set broad rules on which tables a user can read or write. Still, fixed roles do not check individual queries while they run. A user in the datareader role can read every user table and view.
That presents a big problem when an AI agent writes its own SQL. The agent might query tables that hold sensitive customer fields. Native roles return raw emails, phone numbers, card numbers, and national IDs in full. Unless you build custom views for every table, the agent gets all columns.
Kubernetes API Server Access + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static credentials also create a risk for the team. To let the agent log in, you must store a database password in files. If a prompt leaks those local settings, someone could steal the database key. Also, if you give the agent datawriter rights for a test, risk grows. The agent can then delete or change rows in any user table. Native roles cannot pause a dangerous delete statement to ask a human first.
Adding runtime controls for agent queries
A safer setup combines native database roles with checks on every single query. First, you keep the database user locked down with minimal read or write rights. Next, you place runtime rules between the agent worker and the database server.
Runtime checks inspect each SQL statement before the database runs it. If an agent tries to run a drop or delete command, the rule blocks it. You can also require a human to approve specific write statements in real time. Data masking rules can rewrite emails, phone numbers, and card numbers in query results. This keeps sensitive strings out of the language model context window.
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
What is the safest SQL Server role for a read-only AutoGen agent?
Assign the agent user to the fixed datareader role and the denydatawriter role. This lets the agent read user tables while blocking any data changes.
Should I use a standard login or a contained user for the sandbox?
Use a contained database user if the agent only needs one database. This keeps the user isolated from the master database after an admin enables it.
Can native read-only roles stop an agent from reading sensitive columns?
No, the fixed datareader role grants read access to all user tables and views. To hide specific fields like card numbers, you need views or runtime data masking.
Related guides
In this post