CrewAI with Supabase: read-only tools, RLS, and proxy checks
CrewAI with Supabase works best when you treat database access as a three-layer problem. The layers are the tool's safety flags, database row-level policies, and a proxy. The first two layers decide who connects and which rows they see. How CrewAI's NL2SQLTool handles database access CrewAI's NL2SQLTool turns natural language into SQL queries. By default, this tool is read-only. It restricts agents to SELECT, SHOW, DESCRIBE, and EXPLAIN statements. It blocks multi-statement queries in this mo
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.
CrewAI with Supabase works best when you treat database access as a three-layer problem. The layers are the tool's safety flags, database row-level policies, and a proxy. The first two layers decide who connects and which rows they see.
How CrewAI's NL2SQLTool handles database access
CrewAI's NL2SQLTool turns natural language into SQL queries. By default, this tool is read-only. It restricts agents to SELECT, SHOW, DESCRIBE, and EXPLAIN statements. It blocks multi-statement queries in this mode. You must explicitly enable DML support to allow data writes. The CrewAI documentation warns that this allows data modification or destruction. It recommends using least-privilege credentials and guardrails even when DML is allowed.
The tool runs model-generated SQL directly against your connection string. Agent safety depends heavily on the credentials you provide. Broad permissions make the read-only flag just a first line of defense.
Supabase roles, RLS, and the limits of database permissions
Supabase builds on PostgreSQL. It adds API keys and Row Level Security (RLS) to manage access. The default postgres role has admin privileges but is not a superuser. This prevents some of the most destructive operations. Application access uses roles like anon and authenticated. Elevated access uses the service_role. A secret key resolves to the service_role role, which bypasses RLS when the request carries no user access token. This key must never end up in a client-side application or an agent that does not need elevated access.
RLS policies add a WHERE clause to every query a role runs. This restricts which rows a user can see. It does not stop a user from running a destructive statement if they have the grant. For example, a role with DELETE permission can still delete rows. RLS only restricts which rows they can delete. Postgres permissions decide which objects, columns, and rows a role can read. They do not judge query intent or rewrite values. This is a fundamental limitation. Database-level controls are static. They cannot adapt to dynamic statements an AI agent generates in real-time.
Why a proxy is the missing layer for CrewAI with Supabase
The gap between CrewAI tool flags and Supabase RLS policies is where the real risk lives. Database permissions only check if the role has the right to run the operation on the object.
Read-Only Root Filesystem + Database Proxy (ProxySQL, PgBouncer): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
A proxy on the database connection becomes essential here. It sits between the agent and the database. It reads every statement the agent sends and every result that comes back. It inspects the actual SQL, not just the role or table. It decides whether the statement is safe to run.
How hoop.dev fits into the CrewAI with Supabase stack
hoop.dev is an open-source proxy that runs next to your PostgreSQL database. This includes Supabase. It reads the Postgres protocol directly. It sees every statement the agent sends. This includes prepared statements that drivers and ORMs use. Because it speaks the database's own protocol, it can classify each statement by its most consequential effect. A DELETE hidden inside a CTE still counts as a delete. Several statements sent in one message are split and judged one by one.
With hoop.dev, you can set up guardrails. You can refuse statements by effect, table, or pattern. If the agent tries to run a DELETE with no WHERE clause, hoop.dev blocks it. It returns a readable error message to the agent. The agent knows why it was refused. You can also use data masking. This rewrites sensitive values in results before they reach the agent. For more on how these controls work, see the guardrails documentation and the data masking guide.
The agent changes one thing: the host and port in its connection string. It points to the hoop.dev proxy instead of the Supabase database directly. The credentials stay the same. The Supabase RLS policies stay the same. hoop.dev rides next to all of these. It adds a layer of runtime control. It checks every statement and every result.
Setting up the stack
To set this up, start with your Supabase project and CrewAI agent. Create a dedicated database role for the agent. Give it the minimum permissions it needs, such as SELECT on specific tables. Configure RLS policies to restrict which rows the agent can see. Deploy hoop.dev next to your Supabase database. Point the agent's connection string to the proxy. Define guardrails in hoop.dev to block destructive statements. Set up data masking rules for sensitive columns. The exact configuration is documented in the getting started docs. The source code is available on GitHub if you want to see how it works under the hood. You can also check out the hoop.dev repository to explore the code and contribute.
Frequently asked questions
Does hoop.dev replace Supabase RLS?
No. hoop.dev works alongside RLS. RLS restricts which rows a role can see. hoop.dev checks what each statement does and what comes back. They are complementary layers.
Can I use hoop.dev with CrewAI's other database tools?
Yes. hoop.dev sits on the database connection. It works with any tool that connects to PostgreSQL. This includes CrewAI's MySQLSearchTool or MongoDBVectorSearchTool, as long as the protocol is supported.
Does hoop.dev slow down the agent's queries?
hoop.dev adds runtime control that database permissions do not provide. It checks every statement before it reaches the database.
In this post