How to Configure Mastra ClickHouse Sandbox
You set up a mastra clickhouse sandbox by creating a restricted database user. Then you connect your agent tool to that account with read-only permissions. Teams often start by giving their AI agents broad database accounts to move fast. Broad permissions let an agent read sensitive tables or run heavy queries by mistake. A dedicated sandbox user keeps your data safe while agents test and run queries. How a mastra clickhouse sandbox works ClickHouse manages users, roles, row policies, setting
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 mastra clickhouse sandbox by creating a restricted database user. Then you connect your agent tool to that account with read-only permissions. Teams often start by giving their AI agents broad database accounts to move fast. Broad permissions let an agent read sensitive tables or run heavy queries by mistake. A dedicated sandbox user keeps your data safe while agents test and run queries.
How a mastra clickhouse sandbox works
ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL entities. To turn on SQL access control, you set up a storage directory on the server. You also need at least one admin user with access management rights turned on. An admin can only grant privileges that they hold themselves. Creating a new sandbox account requires the privilege to create users.
During user creation, you define how the account logs in and which hosts can connect. You also assign default roles and specific user settings for the agent. Once the account exists, you link it to your Mastra agent workflow. The agent uses this account to run analytical queries against your tables.
To lock down the sandbox, you grant read permissions on specific columns only. When you grant select rights on two columns, the agent can query only those fields. If the agent tries to query a third column, the database blocks the query. A wildcard query across all columns will also fail and return no data. It only works if the table holds just the allowed columns. You can also grant select rights across multiple tables that share a name prefix.
What native database roles solve and what stays exposed
Native ClickHouse roles and column grants control which user can log in and read tables. They stop a Mastra agent from dropping tables or reading forbidden columns. This setup gives you a strong baseline for database safety.
Still, static database grants do not inspect what individual queries do in flight. An allowed column might still hold emails, phone numbers, card numbers, or national IDs. If an agent queries that column, the database returns the raw text to the model. Static grants also cannot require a human to approve a sudden heavy query. You have to update roles across every database server when team rules change.
ClickHouse Access Management + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Managing agent queries and sensitive fields in flight
Running AI agents safely requires checks on every query before and after it runs. Teams need a way to inspect statements in real time and block risky patterns. Dynamic data masking can rewrite emails, phone numbers, and card numbers in query results. This step happens before the data reaches the Mastra agent or the language model. Teams also benefit from a single audit log that records every agent query and user.
Check ClickHouse queries and results before execution
Access control in ClickHouse is essential setup. Setup alone does not check single queries for risk or rewrite sensitive strings in returned rows. By design, hoop.dev sits beside the server as a sidecar for your ClickHouse and parses every statement before execution.
First, hoop.dev guardrails block disallowed deletes, drops, and alter mutations. Then hoop.dev data masking rewrites sensitive string columns in responses and logs each decision per resource. Read the docs and source on GitHub.
Frequently asked questions
How do you limit which columns a Mastra agent can read in ClickHouse?
You grant the select privilege on specific column names for the sandbox user. The agent can then query only those listed columns and wildcard queries will fail.
What do you need to turn on SQL access control in ClickHouse?
You must configure a storage directory on the server for access entities. You also need at least one user account with access management permissions enabled.
Why do column grants alone leave sensitive data exposed to AI agents?
Column grants are all or nothing for each field you allow. If an allowed column contains emails or card numbers, the database returns those raw values.
Teams that document these role rules and review logs each month catch config drift early. Clear ownership for each role keeps live systems simple to run and easy to audit across the whole team.
Related guides
In this post