How to Configure Dify SQL Server Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a dify sql server sandbox by making a read-only database user. Then you link that user account to your AI workflow tool. Teams often start by reusing an existing app login for quick tests. Broad roles let an AI agent change tables or drop the database. How to set up a dify sql server sandbox with native roles First, you must choose how the account logs in to the server. A database user is the identity of a login inside a database. SQL Server supports thirteen types of database user

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 sql server sandbox by making a read-only database user. Then you link that user account to your AI workflow tool. Teams often start by reusing an existing app login for quick tests. Broad roles let an AI agent change tables or drop the database.

How to set up a dify sql server sandbox with native roles

First, you must choose how the account logs in to the server. A database user is the identity of a login inside a database. SQL Server supports thirteen types of database users for different needs. If an agent needs many databases, teams use a login in master. For one database, a contained database user with a password works well. A contained user does not tie to a login in master. An admin must turn on contained databases on the server and database first.

Next, you assign the new user to a fixed database role. All roles, including the public role, have basic permission to connect. You cannot change the permissions built into fixed database roles. Avoid the owner role when you build a sandbox for AI tools. Members of that owner role can run all setup and maintenance tasks. They can even drop the whole database in SQL Server. Instead, add the sandbox user to the fixed data reader role. This role lets the user read all data from user tables. It also lets the user read all views in that database. You can also add the deny data writer role for extra safety. That role stops the user from adding, changing, or deleting any data.

What native roles solve and what they leave open

Native roles control who can log in to the database. They also block write commands when you use read-only roles. This stops an AI agent from deleting rows or changing table data.

Still, fixed roles do not check what individual queries do in flight. A member of the data reader role can read every user table. The role cannot hide specific columns inside a table or view. If a table holds emails or phone numbers, the query reads them. Card numbers and national IDs also flow back in the query results. You can block a whole table with the deny data reader role. That role stops the user from reading data or metadata in tables. Yet doing this across hundreds of tables takes a lot of work. Native roles also do not require human approval before a query runs. Once the user logs in, every read query runs right away.

Kubernetes API Server Access + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why static database passwords create risk in AI apps

To link Dify to your database, you store the user password. Anyone who can edit the AI workflow might see that stored key. If a bad query runs, the database log shows one shared user. You cannot tell which person or prompt triggered that specific query. Rotating that password also means updating both the database and the app.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev is an open-source proxy that sits next to SQL Server as a sidecar for your SQL Server. It inspects TDS batches and parameterized queries in real time.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused with your message. Matched sensitive fields in supported result columns are masked in memory, and each decision is logged per listener. Check out the code on GitHub.

Frequently asked questions

Should I use a login in master or a contained user for a sandbox?

Use a contained database user if the AI app needs one database. It keeps the user and password inside that single sandbox database. Remember to enable contained databases on the server and database first.

Can I edit the fixed data reader role to hide one table?

No, you cannot change the permissions assigned to fixed database roles. The data reader role always reads all user tables and views. You must deny read access on specific objects or use custom roles.

How do I make sure the AI agent cannot write data?

Do not add the user to the owner or data writer roles. Add the user to the fixed data reader role for read access. You can also add the deny data writer role to block changes.

The query runs. The emails stay hidden.