How to Configure Claude Code SQL Server Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You build a claude code sql server sandbox by making a read-only database user. Then you connect the AI agent through a Model Context Protocol server. Teams often connect coding agents to test databases to speed up work. If the database role is too broad, the agent can change or delete data. Giving the agent full owner rights lets it drop the whole database. How to set up a claude code sql server sandbox First, you need to set up the right identity in SQL Server. A database user is the identi

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 build a claude code sql server sandbox by making a read-only database user. Then you connect the AI agent through a Model Context Protocol server. Teams often connect coding agents to test databases to speed up work. If the database role is too broad, the agent can change or delete data. Giving the agent full owner rights lets it drop the whole database.

How to set up a claude code sql server sandbox

First, you need to set up the right identity in SQL Server. A database user is the identity a login uses inside one database. For access to many databases on an instance, teams use a standard login. That login lives in the master database.

For a single sandbox database, a contained database user is a good option. This user has a password and does not tie to a master login. An admin must enable contained databases on the server and the database first. SQL Server supports thirteen types of database users in total.

Next, you assign the user to a fixed database role. 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. You cannot change the permissions assigned to these fixed database roles.

Never give an AI coding agent the database owner role. Members of that role can run all maintenance tasks and drop the database. Note that all roles, including the public role, have basic connect rights.

How Claude Code reaches the database

Claude Code reaches external databases and tools through Model Context Protocol servers. Vendor docs show database queries as a main use case for these servers. You pass a database connection string to the server so the agent can query.

The docs advise using a read-only database user in that connection string. This step ensures the queries the agent runs cannot modify your data. You should also verify that you trust each server before connecting it.

Claude Code Security + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Claude Code can also run shell commands through its built-in Bash tool. In manual mode, this tool asks for approval before running most commands. Only a small set of safe read-only file and git commands run without approval. If a database script runs in the shell, the user must approve it.

What native roles solve and what they miss

Native SQL Server roles control who can log in to the database. They also decide whether a user can read or write table data. A read-only role stops an AI agent from dropping tables or changing rows. This setup works well for basic protection in a test setup.

Still, native database roles do not inspect individual queries while they run. The data reader role lets the agent read every user table and view. If your sandbox holds real customer data, the agent reads all of it.

The database role cannot mask sensitive fields like emails or phone numbers. It cannot rewrite card numbers or national IDs in the query results. Also, a static connection string on a laptop can leak in plain text. Native roles decide who gets in, not what each query does in flight.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

Can I change the permissions of the SQL Server data reader role?

No, SQL Server does not let you change permissions on fixed database roles. The data reader role always grants read access to all user tables and views.

Should I use a standard login or a contained user for a sandbox?

Use a contained database user if the agent only needs one sandbox database. This keeps the user inside that database and avoids a login in master.

How do I stop Claude Code from changing data in SQL Server?

Put a read-only user in your Model Context Protocol server connection string. Add that user to the data reader and deny data writer roles.

The query runs. The emails stay hidden.