How to Configure Vercel AI SDK SQL Server Sandbox
You set up a vercel ai sdk sql server sandbox by creating a read-only database user. Then you wire that user into your AI tool definition. Teams often connect AI apps to databases with broad admin logins to move fast. When permissions are too wide, one bad prompt can delete tables or leak data. Scoping the database user before the AI runs any query reduces that risk. How a vercel ai sdk sql server sandbox works with native roles In SQL Server, a database user is the identity of a login inside
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 vercel ai sdk sql server sandbox by creating a read-only database user. Then you wire that user into your AI tool definition. Teams often connect AI apps to databases with broad admin logins to move fast. When permissions are too wide, one bad prompt can delete tables or leak data. Scoping the database user before the AI runs any query reduces that risk.
How a vercel ai sdk sql server sandbox works with native roles
In SQL Server, a database user is the identity of a login inside a database. When an app needs one or a few databases, a contained user works well. A contained database user has a password and does not need a master login. An admin must first turn on contained databases on the server and database. For apps that touch many databases on an instance, a standard login is common. SQL Server supports thirteen different types of database users for various access needs.
Once the user exists, you assign fixed database roles to control what queries run. Every role in the database, including the public role, has basic permission to connect. You cannot change the built-in permissions that belong to fixed database roles. To make a read-only sandbox, you add the user to the datareader role. Members of this role can read all data from all user tables and views. You can also add the user to the denydatawriter role for extra safety. That role stops the user from adding, changing, or deleting any table data. Avoid the owner role, which can run maintenance tasks and drop the whole database.
How the AI tool calls the database
The Vercel AI SDK lets language models call external tools during a chat flow. You define a database tool with a clear input schema and an execution handler. The language model reads the user prompt and decides to call your SQL tool. It generates a query string and passes that string to your server code. Your server code opens a database session using the sandbox user credentials. The database checks the role of that user and runs the query. Then the tool sends the rows back to the model to write an answer.
What native roles solve and what they leave open
Native SQL Server roles decide which account can log in and read tables. Putting the AI user in the datareader role blocks destructive writes and table drops. If the model writes an update or delete statement, the database rejects it right away. You can also use the denydatareader role to block reads across all user tables.
AI Sandbox Environments + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, fixed roles apply to the whole database rather than individual queries in flight. A user in the datareader role can read every row in every user table by default. If a table holds customer emails, phone numbers, or card numbers, the query returns them. The fixed role cannot rewrite those matched fields in the query results by itself. Also, native roles do not pause a risky query to ask a human first. They only check who logged in, not what each generated statement tries to pull.
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. It reads plain batches and parameterized queries on the TDS wire while passing Windows login through untouched.
Before a batch hits the server, hoop.dev guardrails check the statement against your rules. Disallowed actions get a native TDS error with your message. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns that match your rules. Every query and decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Should I use a standard login or a contained user for an AI sandbox?
Use a contained database user if the AI app only queries one database. It keeps the user isolated to that database without needing a login in master. Remember that an admin must turn on contained databases on the server and database first.
Does the datareader role hide sensitive columns from the AI model?
No, members of the datareader role can read all data from all user tables. It grants read access to every column and view inside that database by default. To keep emails or card numbers out of results, you need column permissions or masking.
How can I be sure the AI sandbox user never writes data?
Keep the user out of the datawriter and owner roles when you set it up. You can also add the user to the denydatawriter role inside the database. That role blocks the user from adding, changing, or deleting data in user tables.
Related guides
In this post