How to Configure Claude Code MySQL Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a claude code mysql sandbox with an MCP server or shell tool. You pair that tool with a dedicated, read-only database user for safety. Engineering teams often give coding agents broad database credentials to move fast. Those wide permissions let an automated prompt change tables or drop data by mistake. A restricted test database keeps agent queries away from live production systems. How a claude code mysql sandbox works Claude Code talks to outside systems and databases in two mai

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 claude code mysql sandbox with an MCP server or shell tool. You pair that tool with a dedicated, read-only database user for safety. Engineering teams often give coding agents broad database credentials to move fast. Those wide permissions let an automated prompt change tables or drop data by mistake. A restricted test database keeps agent queries away from live production systems.

How a claude code mysql sandbox works

Claude Code talks to outside systems and databases in two main ways. The first way uses the Model Context Protocol, also known as MCP. MCP servers give the coding agent access to your tools, databases, and APIs. You point an MCP database server at your MySQL instance with a connection string. Official docs advise using a read-only database user inside that connection string. Then the queries the agent runs cannot change or delete your stored data. The docs also warn you to verify that you trust each MCP server first.

The second way uses the built-in Bash tool to run local shell commands. In Manual mode, the agent asks for your approval before running shell commands. Only a small built-in list of safe read commands runs without a prompt. When the agent runs a database client in the shell, you must approve it. Both paths rely on the MySQL user role you assign to the session.

Setting up database roles for agent access

Start by creating a separate MySQL instance or a dedicated test schema. Load this space with fake test rows instead of real customer records. Next, create a new MySQL user account built just for the coding agent. Grant this user select rights only on the specific tables it needs to read. Do not grant write, update, delete, or table change rights to this account.

Put these read-only login details into your local MCP server setup. When the agent needs to check a schema, it calls the MCP server. The server logs in to MySQL with the restricted role and runs the query. If you use the Bash tool instead, keep the agent in Manual mode. Check every database command the agent wants to run before you say yes.

Claude Code Security + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database sandboxes leave open

A native MySQL role controls who logs in and which tables they can read. It does not inspect what individual queries do while they run in flight. A read-only user can still pull thousands of rows in a single query. If your test database holds copied production data, the agent reads real user info. Those raw emails, phone numbers, and card numbers go straight into the model context.

Local config files also store static database passwords on developer laptops. Anyone with access to that machine can read the plain text connection string. Also, MySQL logs show the shared role name instead of the developer's real identity. When a bad query slows down the database, you cannot see who triggered it. Teams need query-level controls and data masking to close these operational gaps.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

How does Claude Code connect to a MySQL database?

It connects through an MCP server configured with a database connection string. It can also run local database client commands through its built-in Bash tool.

Why does the agent need a read-only MySQL user?

A read-only user stops the agent from running write or delete queries. This setup protects your tables if the model writes a bad SQL statement.

Does Manual mode stop all unsafe database queries?

Manual mode asks for user approval before the Bash tool runs a command. Still, it does not mask sensitive fields like emails or card numbers in results.

The query runs. The emails stay hidden.