How to Configure Dify MySQL Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a dify mysql sandbox by creating a read-only database role for your AI app. Next, you add those database keys to your custom tool node inside the workflow builder. Teams often start by reusing a broad admin user to test their first agent prompts. That shortcut lets an AI workflow change rows, drop tables, or read private user tables. A safer plan isolates your test database and limits what the agent role can read. How a dify mysql sandbox works in your stack The platform runs an is

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 dify mysql sandbox by creating a read-only database role for your AI app. Next, you add those database keys to your custom tool node inside the workflow builder. Teams often start by reusing a broad admin user to test their first agent prompts. That shortcut lets an AI workflow change rows, drop tables, or read private user tables. A safer plan isolates your test database and limits what the agent role can read.

How a dify mysql sandbox works in your stack

The platform runs an isolated execution service that handles custom code and external tool calls. When an agent runs a task, the workflow engine passes parameters to that tool worker. The worker opens a direct database session using the static user keys stored in your workspace. It then sends the generated SQL statement to your test server and waits for results.

Your database checks the user role and permissions when the session starts. If the role allows read queries on a table, the database runs the statement. The database sends the matching rows back to the tool worker as plain text. Finally, the worker hands those rows to the language model to build the chat reply.

How to set up native database roles and network rules

Start by spinning up a separate database instance that holds only test or synthetic records. Never point an experimental agent workflow straight at your main production database cluster. Inside the test instance, create a dedicated database user just for your AI agent tasks. Grant that user select permissions only on the specific tables the workflow needs to read.

Do not grant permissions to write data, alter schemas, or read system tables. Next, set a query timeout on the database user so bad joins cannot lock CPU. You also need to lock down network paths between the app worker and your database. Update your firewall rules so the test database only accepts traffic from the worker host. Enable TLS on the database session so queries and results travel over an encrypted link.

MySQL Access Governance + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and where gaps remain

A dedicated read-only user stops the agent from deleting rows or changing table structures. Separate test instances also keep heavy test queries away from your live customer traffic. Still, native database roles only check who logs in and which tables they can read. Once the session starts, the database cannot tell which end user triggered a specific query.

Every query in the database log shows the exact same shared app user account. If a table holds emails, phone numbers, or card numbers, a select query pulls them all. Data masking that rewrites matched fields in results is missing from basic database user roles. Native roles also cannot pause a risky query to ask a human for approval first. Teams need query-level controls to run agents against real data without exposing sensitive fields.

Add wire guardrails and masking beside MySQL

Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev runs beside the database as a sidecar for your MySQL. It keeps your login setup and drivers as they are while checking queries on the wire.

With hoop.dev MySQL support, guardrails refuse bad queries before they run and return a readable MySQL error. Data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.

Frequently asked questions

Can I use my main database user for a dify mysql sandbox?

No, using a main admin user gives the AI agent full write and delete rights. Always create a separate user with read-only access to specific test tables.

Does the built-in code sandbox isolate my external database queries?

No, the built-in code sandbox only isolates local scripts running inside the platform worker. Once your tool sends a query out to a database, your database rules take over.

How do I keep test queries from exposing private fields like emails?

Keep private records out of your test tables, or apply dynamic data masking rules. Masking rewrites matched fields like emails, phone numbers, and card numbers in query results.

The query runs. The emails stay hidden.