How to Configure LlamaIndex CockroachDB Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a llamaindex cockroachdb sandbox by giving the query engine a read-only database role and naming only safe tables. This setup stops the AI agent from changing rows or pulling your whole schema into prompts. Most teams start by handing their app a wide admin user to test text-to-SQL fast. That wide role lets generated SQL read private rows or drop tables by mistake. A strict setup fixes this risk before your agent runs in production. How a llamaindex cockroachdb sandbox works in prac

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 cockroachdb sandbox by giving the query engine a read-only database role and naming only safe tables. This setup stops the AI agent from changing rows or pulling your whole schema into prompts. Most teams start by handing their app a wide admin user to test text-to-SQL fast. That wide role lets generated SQL read private rows or drop tables by mistake. A strict setup fixes this risk before your agent runs in production.

How a llamaindex cockroachdb sandbox works in practice

LlamaIndex connects to SQL databases through a light wrapper around SQLAlchemy. You pass a database engine into that wrapper to start a session. Then the natural language query engine turns user questions into SQL statements. It runs those generated SQL statements straight against your CockroachDB cluster.

If you do not list specific tables, the query engine pulls all schema context. That wastes prompt tokens and shows sensitive table names to the model. To build a safe llamaindex cockroachdb sandbox, you must pass an explicit list of allowed tables. You also set up a restricted database role inside CockroachDB first. That role should only have permission to read the exact tables in your list. The official LlamaIndex docs warn that running arbitrary SQL carries real security risks. They tell teams to use restricted roles, read-only databases, and sandboxing.

What native roles solve and what they leave open

Database roles and table lists solve the first layer of access control. A read-only user ensures the agent cannot run delete or update commands. Naming allowed tables keeps unrelated schema details out of the model prompt. This native setup decides which account can log in and which tables it sees.

Still, static roles do not check what individual SQL statements do in flight. An allowed table might still hold emails, phone numbers, card numbers, or national IDs. Once the database role has read rights on a table, it can read every column and row by default. A single bad prompt can trick the query engine into asking for all customer emails. The database sees a valid select statement from an approved user and returns the rows. Native roles also do not pause risky queries for human review before they run.

AI Sandbox Environments + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Adding table and column limits for AI queries

Teams often create separate database views to narrow down what the agent can query. A view can leave out columns that hold card numbers or national IDs. You then grant the sandbox user read rights only on those clean views. You also pass only those view names to the LlamaIndex query engine.

This approach works well for small apps with a few static tables. Yet views take extra work to maintain as your schema grows across teams. Every schema change means someone must update views and role grants by hand. When many agents query different clusters, tracking these manual rules gets hard. You still need a way to inspect queries and mask sensitive fields in results.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Why does LlamaIndex pull the whole database schema by default?

The SQL query engine needs table definitions so the model can write valid SQL. If you do not specify table names, the wrapper inspects every table available to that user. Passing a short table list keeps the prompt small and hides other tables.

Can a read-only CockroachDB user still leak sensitive data to an LLM?

Yes, a read-only role only stops writes, updates, and schema changes. It still lets generated select queries pull every row from allowed tables. If those tables contain phone numbers or emails, those values go straight into the model context.

What precautions do the LlamaIndex docs suggest for text-to-SQL?

The official docs states that executing arbitrary SQL queries is a security risk. It recommends using restricted database roles, read-only databases, and sandboxing to limit what generated queries can touch.

The query runs. The emails stay hidden.