How to Configure LlamaIndex Supabase Sandbox
You set up a llamaindex supabase sandbox by creating a read-only Postgres user. Then you limit the tables that the query engine can read. Many teams start by giving their AI app the main project password. That password belongs to the default admin role in Supabase. When a language model uses an admin role, it can change or delete data. One bad prompt can wipe a table or pull private rows. How a llamaindex supabase sandbox works LlamaIndex connects to Postgres through a light wrapper around SQ
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 llamaindex supabase sandbox by creating a read-only Postgres user. Then you limit the tables that the query engine can read. Many teams start by giving their AI app the main project password. That password belongs to the default admin role in Supabase. When a language model uses an admin role, it can change or delete data. One bad prompt can wipe a table or pull private rows.
How a llamaindex supabase sandbox works
LlamaIndex connects to Postgres through a light wrapper around SQLAlchemy. Its natural language query engine turns user questions into SQL queries. You can pass a list of allowed tables to this query engine. If you skip that list, the engine pulls all schema context from the database. Pulling every table wastes tokens and exposes sensitive tables to the model.
The official LlamaIndex guides warn that running generated SQL is a security risk. They advise teams to use restricted roles, read-only databases, and sandboxing. On the database side, every Supabase project comes with a default Postgres role. This role has admin rights, though Supabase blocks full superuser access to prevent destructive tasks. The password you pick at project setup belongs to this admin role.
Supabase says you should never share this main password with an external service. Instead, you should make a new Postgres user for your AI app. In a sandbox setup, you grant this new user read rights on specific tables only. You also keep it away from private schemas and system tables.
What native roles solve and what they miss
A restricted Postgres user stops the query engine from dropping tables or changing rows. Limiting the table list in LlamaIndex also keeps the model focused on safe schemas. Together, these two steps form a solid baseline for a database sandbox. They decide which account logs in and which tables that account can see.
Still, database roles only check permissions at login and table level. They do not inspect what an individual SQL statement does in flight. A read-only user can still run a slow query that locks up the database. It can also select every row from an allowed table in one request.
AI Sandbox Environments + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
If an allowed customer table holds emails, phone numbers, or card numbers, the query returns them. Native roles cannot rewrite matched fields in results before the model reads the output. You also have to store a database password in your app settings. If someone leaks that key, an attacker gets direct read access to your sandbox tables.
Adding statement checks and field masking
To close these gaps, teams put runtime checks between the agent and the database. Before a generated query runs, a check can block full table scans or unsafe joins. If a query asks for sensitive columns, data masking rewrites matched fields in results. Emails, phone numbers, and national IDs get replaced with safe tokens in flight. This keeps raw personal data out of model prompts while letting queries finish.
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
Why should I avoid the default postgres role for LlamaIndex?
The default postgres role in Supabase has admin privileges across your project. If LlamaIndex runs generated SQL with this role, a bad prompt can alter or delete data. Supabase advises creating a separate user with limited rights for each service.
What happens if I do not name tables in the LlamaIndex query engine?
If you do not pass a table list, the engine pulls all schema context from Postgres. This exposes every readable table to the language model and increases prompt size. Naming specific tables keeps the agent inside the boundaries you choose.
Does a read-only Postgres role hide sensitive columns from AI agents?
No, a basic read-only table grant lets the agent read every column in that table by default. If the table stores emails or card numbers, the query returns those values to the model. You need column grants, views, or result masking to rewrite those fields.
Related guides
In this post