How to Configure OpenAI Agents SDK SQL Server Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk sql server sandbox with a restricted database user. Then you bind that user to a read-only database role for your agent tool. Many teams start by giving an agent a full owner role during tests. That broad role lets a bad prompt alter tables or drop the whole database. How to set up an openai agents sdk sql server sandbox First, you need a dedicated identity inside your database for the agent app. In SQL Server, a database user is the identity of a login. When a

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 openai agents sdk sql server sandbox with a restricted database user. Then you bind that user to a read-only database role for your agent tool. Many teams start by giving an agent a full owner role during tests. That broad role lets a bad prompt alter tables or drop the whole database.

How to set up an openai agents sdk sql server sandbox

First, you need a dedicated identity inside your database for the agent app. In SQL Server, a database user is the identity of a login. When a tool needs many databases, admins often create a login in master. When an agent needs one database, you can use a contained database user. A contained user has a password and does not tie to master. An admin must first turn on contained databases on the server and database. SQL Server supports thirteen types of database users for different needs.

Next, you place that database user into a fixed database role. Fixed roles have set rules that an admin cannot change. The data reader role lets the user read all user tables and views. You can also add the deny data writer role for extra safety. That role stops the user from adding, changing, or deleting any table data. Avoid the database owner role for any agent tool. Members of the owner role can run maintenance tasks and drop the database. Every role, including the public role, includes the basic right to log in.

Finally, you wire the agent tool to run queries through this database user. Your Python code takes the query string from the model and sends it. The database checks the role of the user before it runs the query.

What native database roles solve and what they miss

Native database roles solve the first problem of agent access. They stop an agent from writing data or dropping tables on the server. If the model writes a delete statement, the deny writer role blocks it. This setup keeps your core tables safe from bad changes or drops.

Still, a database role only checks who logs in at the table level. It does not check what a single select query does in flight. A member of the data reader role can read every user table. It can also read every view in that database without limits. If a table holds emails, phone numbers, or card numbers, the agent reads them. The database sends those raw fields right back to the model context.

Kubernetes API Server Access + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Fixed roles also cannot stop a model from running a huge join query. A bad select statement can lock tables or slow down the whole server. You cannot change the rules inside a fixed database role to block specific columns. To fix this safely, teams need controls that check each statement and mask fields.

How to keep test data safe from bad agent queries

Start by keeping your sandbox database separate from your live production instance. Load fake rows into your user tables so the agent can test logic. If you must use real table structures, strip out real national IDs first. Replace real emails and phone numbers with fake values before the agent runs.

You should also limit which tables the agent can see in its prompt. Do not hand the entire schema context to the model at once. Name only the few tables that the agent needs for its task. When the agent knows fewer tables, it writes simpler and safer select queries. Check your database logs often to see what queries the agent sends. Reviewing these logs helps your team spot bad prompt patterns early.

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. It reads plain batches and parameterized queries on the TDS wire while passing Windows login through untouched.

Before a batch hits the server, hoop.dev guardrails check the statement against your rules. Disallowed actions get a native TDS error with your message. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns that match your rules. Every query and decision is logged. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can a SQL Server data reader role stop an agent from reading sensitive columns?

No, the fixed data reader role grants read rights to all user tables and views. You cannot edit the permissions of a fixed database role to hide specific columns.

Why should I avoid the database owner role for an AI agent sandbox?

The database owner role allows all setup and maintenance tasks on the database. An agent with this role can change rules, delete rows, or drop the database.

What is the benefit of a contained database user for an agent sandbox?

A contained user logs straight into one database without a login in master. This keeps the agent tied to your sandbox database and away from other databases.

The query runs. The emails stay hidden.