How to Configure Mastra Supabase Sandbox
You set up a mastra supabase sandbox by creating a custom database user for your AI agent. Then you grant that user read or write rights on specific test tables. Teams often start by pasting the default database password into their agent settings. That shortcut gives the agent full admin control over every table in the project. If a prompt goes wrong, the agent can drop tables or read private records. How a mastra supabase sandbox works with database roles Every new Supabase project comes wit
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 supabase sandbox by creating a custom database user for your AI agent. Then you grant that user read or write rights on specific test tables. Teams often start by pasting the default database password into their agent settings. That shortcut gives the agent full admin control over every table in the project. If a prompt goes wrong, the agent can drop tables or read private records.
How a mastra supabase sandbox works with database roles
Every new Supabase project comes with a default postgres role. This default role holds admin rights across the database. Supabase does not grant full superuser status to prevent harmful system actions. Still, the default postgres password unlocks almost everything inside your project. You should never share this password with an outside tool or an AI agent.
Instead, Supabase recommends making a fresh database user for each external service. When you run queries in the project dashboard, they run as the default postgres role. You can use that dashboard to create a dedicated role for your Mastra workflow. This keeps your agent isolated from your main admin account.
Each project also includes built-in roles like anon for public requests. When you build an agent test bed, a custom role works best. You give this role access only to the schemas and tables meant for testing. Your Mastra agent logs in with this scoped role to run its tasks.
What native roles solve and what they leave open
Custom database roles solve the first step of access control. They decide who can log in to your test database. They also limit which tables the agent can see or change. If your Mastra tool only needs to read product data, role permissions block table deletes. This stops basic mistakes before they touch your main schema.
Still, static database roles only check permissions at login and table level. They do not inspect what individual queries do while running in flight. Once logged in, the agent can run any allowed query on an open table. It might pull thousands of rows at once or read sensitive test columns.
AI Sandbox Environments + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles also cannot rewrite sensitive fields inside query results on the fly. If a test table holds real emails, phone numbers, card numbers, or national IDs, the query returns them. Data masking is needed to rewrite matched fields in results before the agent processes them. Teams also need query-level logs tied to the exact agent task, not just shared role names.
Steps to scope your agent database setup
Start by listing the exact tables your Mastra agent needs for its workflow. Open your Supabase project dashboard, where queries execute under the admin postgres role. Create a new database user built just for your Mastra test runs. Assign a strong password to this new user and store it safely.
Next, revoke default public access from this new role so it starts with zero rights. Grant select or insert permissions only on the specific sandbox tables you picked earlier. Connect your Mastra agent to the database using these new user details. Test a few sample agent prompts to confirm that blocked tables return permission errors.
Run guardrails and masking on the Postgres connection
Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.
On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.
Frequently asked questions
Should I use the default postgres role for my Mastra agent?
No, the default postgres role has admin rights across your project. Supabase advises creating a separate database user for every third-party service or agent.
Why does Supabase block superuser access on the default role?
Supabase withholds superuser access because it allows destructive actions on the database system. Instead, the platform grants the default postgres role extra rights for safe admin tasks.
Can database roles hide emails or card numbers in query results?
Standard roles grant or block access to whole tables or columns. They do not rewrite matched fields like emails or card numbers inside returned query results.
Related guides
In this post