How to Configure Pydantic AI Supabase Sandbox
You set up a pydantic ai supabase sandbox by creating a restricted database user for your agent. Next, you pass that database login into your agent tool dependency settings. Teams often start by handing the default admin password to their agent tools. That approach gives the model full admin privileges over every table in the project. If a prompt goes wrong, the agent can drop tables or read private records. A safe test setup starts with strict database roles and clear table rules. How a pyda
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 pydantic ai supabase sandbox by creating a restricted database user for your agent. Next, you pass that database login into your agent tool dependency settings.
Teams often start by handing the default admin password to their agent tools. That approach gives the model full admin privileges over every table in the project. If a prompt goes wrong, the agent can drop tables or read private records. A safe test setup starts with strict database roles and clear table rules.
How a pydantic ai supabase sandbox works with database roles
Every new Supabase project comes with a default postgres role that holds admin privileges. Supabase does not grant full superuser status because superusers can run destructive database operations. Even so, the default admin password is too powerful for an AI agent tool. Supabase recommends that you create a new database user for every outside service.
Notice that queries run in the web dashboard execute as this admin role. So, you should not test agent limits using the web SQL editor alone. Instead, create a dedicated role for your agent and grant only select privileges. Each Supabase project also includes built-in roles like anon for basic API requests.
In your Python code, the agent framework uses typed tools to run database work. You pass a database client into the run context so tools can run queries. When the model decides to fetch data, it calls your Python function with inputs. The framework checks the input types before the function sends the query to Postgres.
What native roles solve and what they leave open
Native Postgres roles decide which user can log in and which tables they touch. If you revoke write rules, the database blocks the agent from deleting any rows. This setup stops basic accidents when you test new prompts in a test project.
AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static database roles only check permissions at login and table level. They do not inspect what individual queries do while they run in flight. A read-only agent role can still pull thousands of customer emails in one query. It can also read phone numbers, card numbers, or national IDs from allowed tables.
Input validation in your Python code checks data types, not the database results returned. When an agent writes its own SQL, static roles cannot approve single risky statements. Teams also struggle to see which prompt triggered a specific database query across runs. You still have to rotate shared passwords stored in local developer files by hand.
Check every Postgres query on the wire
Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres. It runs beside your database and reads the Postgres wire protocol. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.
Before a query runs, hoop.dev guardrails check the statement by its effect, table, or pattern. They refuse bad deletes or drops with a real Postgres error. On the way back, hoop.dev data masking rewrites sensitive values in returned rows based on your rules. Every query and verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.
Frequently asked questions
Should I give the default Supabase postgres password to my AI agent?
No, the default postgres role has admin privileges across your entire database project. You should create a separate database user with narrow table rules for your agent.
Why do queries behave differently in the Supabase dashboard than in my agent?
Queries in the Supabase web dashboard always run under the default admin postgres role. Your agent runs with the specific role and rules tied to its own login.
Can Pydantic validation stop an agent from reading sensitive columns?
Input checks only validate the arguments before your Python function runs the database query. You need database column rules or result masking to rewrite emails and card numbers.
Related guides
In this post