How to Configure Dify MariaDB Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a dify mariadb sandbox by linking your AI workflow to an isolated database instance with a read-only user role. You store the database host, port, and user key inside your workspace tool settings so agents can run SQL queries. Many teams start by reusing a broad admin user to test their first agent fast. That wide role lets a single bad prompt change rows, drop tables, or pull sensitive user records. How the native dify mariadb sandbox setup works A safe setup starts inside the dat

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 mariadb sandbox by linking your AI workflow to an isolated database instance with a read-only user role. You store the database host, port, and user key inside your workspace tool settings so agents can run SQL queries. Many teams start by reusing a broad admin user to test their first agent fast. That wide role lets a single bad prompt change rows, drop tables, or pull sensitive user records.

How the native dify mariadb sandbox setup works

A safe setup starts inside the database engine before you touch the AI builder. You create a separate database instance or schema that holds only sample or non-critical data. Next, you create a dedicated database user account just for your AI agent workflows. You grant this user read-only rights on the specific tables the agent needs to read. You leave out permissions that allow table drops, row deletes, or schema changes.

Once the database role is ready, you move to the AI workspace. You add a custom tool or database node inside your agent workflow. This node takes the database address, the schema name, and the read-only user key. When a user asks a question, the language model writes a SQL statement. The workflow sends that SQL statement to the database using the static user key. The database runs the query and returns the matching rows back to the model.

Teams also set query timeouts and row limits on the database user account. If the model writes a slow join across large tables, the database stops the query. This basic limit keeps a bad prompt from locking up CPU and memory on the database host.

Why teams copy production data into test instances

Empty test tables rarely catch bad prompts or broken SQL logic. Models need real column values and text formats to build good queries. Because of this, engineers often dump production tables and load them into the test database. This shortcut helps the team test real questions right away.

Still, a production dump brings real customer data into a lower test space. The test tables now hold real emails, phone numbers, card numbers, and national IDs. Every prompt test can pull those fields into the model context and chat logs. Even with a read-only role, the database still sends raw values back to the app.

AI Sandbox Environments + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database roles solve and what they miss

Native database roles do a good job of stopping basic write actions in a test space. A read-only grant stops an agent from deleting rows or changing table structure. Schema limits also keep the workflow out of internal system tables and other project data. For simple test data, these built-in database controls give you a solid starting baseline.

Still, native database permissions only check who logs in at the start of a session. They do not inspect what each generated SQL statement tries to do in flight. If the read-only table holds emails or card numbers, the database sends them out in full. Native roles cannot rewrite matched fields in results before the model reads the output. You also lack a clear audit trail that ties a specific app user to each database query. Every query in the database log just shows the same shared service account name.

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 is an open-source proxy that runs as a sidecar for your MySQL. It reads plain queries, prepared statements, and cursors on the wire.

First, hoop.dev guardrails block banned actions before MySQL runs them. An AI Analyzer you configure can score intent, and hoop.dev data masking rewrites sensitive string columns in results. Every query and verdict goes to the resource audit trail. Find the open-source binary on GitHub.

Frequently asked questions

What database permissions should a Dify agent have in a MariaDB sandbox?

Give the agent user read-only select permissions on the exact tables it needs to query. Never grant drop, delete, update, or grant rights to an account used by an AI workflow.

How do you stop a language model from running slow queries in MariaDB?

Set resource limits on the MariaDB user account to cap query run time and max connections. You can also expose smaller summary views instead of raw tables with millions of rows.

Can a read-only MariaDB user still expose sensitive data to Dify?

Yes, a read-only role can still read every column in an allowed table by default. If those columns hold emails, phone numbers, or card numbers, the query returns them unless masking rewrites matched fields in results.

The query runs. The emails stay hidden.