How to Configure LangChain CockroachDB Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a langchain cockroachdb sandbox by giving your agent a restricted database role. You then point the agent tool to an isolated test cluster or schema. Teams often start by handing the agent a broad admin login to move fast. That shortcut lets a bad prompt alter tables or read sensitive rows across the cluster. A safe setup pairs native database roles with strict query and field controls. How a langchain cockroachdb sandbox works An AI agent reads plain text questions and turns them

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 langchain cockroachdb sandbox by giving your agent a restricted database role. You then point the agent tool to an isolated test cluster or schema. Teams often start by handing the agent a broad admin login to move fast. That shortcut lets a bad prompt alter tables or read sensitive rows across the cluster. A safe setup pairs native database roles with strict query and field controls.

How a langchain cockroachdb sandbox works

An AI agent reads plain text questions and turns them into SQL queries. The agent then runs those queries and returns the results to the user. Because CockroachDB speaks the standard Postgres wire protocol, standard SQL tools work well here. You first create an isolated database or schema inside your CockroachDB cluster. Next, you create a dedicated database user just for the AI agent.

You grant that user read permissions on the safe sandbox tables only. You leave out permissions for creating, changing, or dropping any tables. You also revoke permissions on system catalogs and production schemas. On the client side, you pass this restricted login to your LangChain database wrapper. You can also tell the tool wrapper which table names to include. The agent inspects those allowed tables first so it knows the column names. Then it builds a query and sends it over the database session.

Why native roles are only the first step

Native database roles decide who can log in and which tables they can read. They stop an agent from dropping a production table or writing bad data. Still, table grants do not inspect what individual SQL statements do in flight. Every query from the agent shares the exact same database user login. When you check the database logs later, every action looks the same. You cannot tell which user prompt or app job triggered a bad query.

Table permissions also work on an all-or-nothing basis for each allowed table. If a sandbox table holds real customer emails or phone numbers, the agent reads them. A read-only grant cannot rewrite sensitive fields like card numbers or national IDs. An agent can also write a heavy join that locks up cluster resources. Native grants verify the login at the start of the session. They do not filter columns on the fly or block risky queries before execution.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Adding query and data controls for AI agents

To close this gap, teams put statement checks and data masking in the middle. Before a query reaches CockroachDB, a check inspects the SQL command structure. You can block specific query types even if the database role allows them. You can also hold risky statements for a human to approve in Slack. When the database sends rows back, field masking rewrites matched fields in results.

Emails, phone numbers, and card numbers get replaced before the model reads the output. This keeps private data out of model prompts and third-party chat logs. Every query also gets tied to the specific service or user that asked for it. That gives your security team a clear audit trail for every single agent run.

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

How do I keep a LangChain agent from changing data in CockroachDB?

Create a dedicated database role that only holds select grants on your sandbox tables. Do not give the agent role insert, update, delete, or schema change permissions. You can also add query rules that block any write statements in flight.

Can I restrict which tables the LangChain SQL tool inspects?

Yes, the database wrapper lets you specify a list of included tables. Combining that setting with strict database grants keeps the agent focused on safe tables. Always enforce the limit in the database role as well as the app code.

How do I protect test tables that still contain real emails or card numbers?

Database table grants cannot hide part of a value inside an allowed column. Use dynamic data masking to rewrite emails, phone numbers, and card numbers in query results. This lets the agent test real query logic while keeping sensitive values masked.

The query runs. The emails stay hidden.