How to Configure Gemini CLI SQL Server Sandbox
You set up a gemini cli sql server sandbox by creating a restricted database user. Then you point your local agent tools to that non-production database instance. Many teams start by giving the coding agent a shared admin account. That broad role lets the agent change schemas or delete test data by mistake. A dedicated sandbox user limits what the agent can do when it connects. How to set up a gemini cli sql server sandbox First, you need to pick the right identity type in SQL Server. A datab
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 a gemini cli sql server sandbox by creating a restricted database user. Then you point your local agent tools to that non-production database instance. Many teams start by giving the coding agent a shared admin account. That broad role lets the agent change schemas or delete test data by mistake. A dedicated sandbox user limits what the agent can do when it connects.
How to set up a gemini cli sql server sandbox
First, you need to pick the right identity type in SQL Server. A database user represents the identity of a login when it connects. If the agent needs many databases on one server, use a standard login. That login lives in the master database and maps to each target database. If the agent only needs one sandbox database, use a contained database user. A contained user has a password and stays inside that single database. Your admin must enable contained databases on the server and database first.
Next, you assign the user to fixed database roles to control permissions. You cannot change the permissions built into fixed database roles. Every role, including the public role, includes basic connection rights. To let the agent read all user tables and views, use the datareader role. If the agent must insert, change, or delete rows, add the datawriter role. You can also block actions with deny roles. The deny datawriter role stops the user from changing any table data. The deny datareader role blocks all reads from user tables and views. Never put the sandbox user in the database owner role. Database owners can run all maintenance tasks and even drop the whole database.
Finally, you connect the coding agent to the database from your workstation. Terminal agents run shell commands or talk to local tool servers on your machine. You store the sandbox user credentials in your local shell variables or tool settings. When you ask a question, the agent uses those credentials to run queries.
What native database roles solve and what they miss
Native SQL Server roles do a good job of controlling basic table permissions. They decide who can log in and which tables they can read or write. Putting an agent in a read-only role stops it from dropping tables. Using a deny role ensures the agent cannot edit rows in a test database. This setup protects your sandbox from accidental writes during normal coding tasks.
Still, static database roles only check permissions when the session starts. They do not inspect individual queries while they run in flight. A read-only role still lets the agent read every row in every user table by default. If your sandbox holds copied production data, those tables often contain real secrets. The agent can pull emails, phone numbers, card numbers, and national IDs into prompts. Native roles cannot rewrite matched fields in results to hide those sensitive values.
Kubernetes API Server Access + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static roles also force you to store database passwords on developer laptops. Any script or terminal process on that machine can read those saved credentials. Also, database roles cannot pause a risky command to ask for human approval. If you give the agent write rights for one task, it keeps them forever. The database cannot tell if a delete statement came from a human or an agent.
Why sandbox databases still carry data risks
Many teams refresh their sandbox by restoring a backup from production. Even when teams try to scrub data, new columns often slip through unchecked. When a coding agent queries those tables, it sends the results to model APIs. Reading a table with customer phone numbers or card numbers exposes that data outside. You need controls that work at the query and field level, not just login.
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, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Should I use a login or a contained user for a SQL Server sandbox?
Use a contained user if the agent only needs one sandbox database. It keeps the user and password inside that single database without touching master. Use a server login if the agent must query several databases at once.
Can the fixed datareader role hide sensitive columns from Gemini CLI?
No, the fixed datareader role grants read access to all user tables and views. You cannot alter the permissions of a fixed database role in SQL Server. It will return raw emails, phone numbers, and card numbers if they exist.
Why should I avoid giving the database owner role to a coding agent?
Members of the database owner role can run all setup and maintenance tasks. An agent with this role can change permissions or drop the entire database. Always use narrower roles so a bad prompt cannot destroy your sandbox.
Related guides
In this post