How to Configure OpenAI Agents SDK CockroachDB Read Only Access
You set up openai agents sdk cockroachdb read only access with a restricted database role. You then bind that role to the custom query tool your agent runs. Most teams start by reusing a general app login during early testing. Broad database permissions let an agent alter tables or delete rows by mistake. A dedicated read role stops write queries before they change any production data. How openai agents sdk cockroachdb read only access works The agent framework uses Python functions as tools
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 openai agents sdk cockroachdb read only access with a restricted database role. You then bind that role to the custom query tool your agent runs. Most teams start by reusing a general app login during early testing. Broad database permissions let an agent alter tables or delete rows by mistake. A dedicated read role stops write queries before they change any production data.
How openai agents sdk cockroachdb read only access works
The agent framework uses Python functions as tools to interact with external systems. You write a function that opens a database session and runs a query. The language model reads the user prompt and decides when to call that function. It generates the SQL text and passes it into your Python tool. The tool sends that query straight to the CockroachDB cluster over the network.
To keep the database safe, you create a dedicated user inside CockroachDB. You grant this user select privileges on the specific tables the agent needs. You revoke all insert, update, delete, and schema change rights from this role. Your Python tool uses these restricted credentials when it logs in to the database. If the model writes a drop or update statement, the database rejects it.
You can also set read-only session modes inside the database client driver. This adds a second check inside the app before the query runs. Both the client driver and the database engine now block any write attempts. Teams store the database key in a local secret store on the host. The agent app reads that secret at startup and opens its database pool.
What native database roles solve and what they miss
Native database roles do a great job of blocking unwanted data writes. They make sure an agent cannot drop a table or corrupt a record. They also let database admins control which tables the agent can read. This setup handles basic login checks at the database cluster boundary.
Still, a read-only role only checks who logs in at the table level. It does not inspect what individual queries do once the session is open. An agent with select access on a customer table can still read every column. If a table holds emails, phone numbers, or card numbers, the query returns them. The raw values go right into the model context and external API logs.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Database roles also share one static login across every user who triggers the agent. Every query in the database log shows the exact same service account name. Audit teams cannot tell which human user or prompt caused a specific query. Also, the agent host still holds long-lived database keys in its memory. If a prompt flaw exposes the host, those keys are at risk. Finally, a read role cannot stop an agent from running a massive table scan. One bad select query can still lock up memory and slow down the cluster.
Reducing blast radius for agent database tools
Teams can shrink the exposure window by splitting tables into smaller views. Database views let you expose only the safe columns to the agent role. You leave sensitive columns like national IDs out of the view definition. You then grant the agent role select rights on the view alone. This takes manual database work every time the schema or app changes.
You should also set statement timeouts on the database role used by the agent. A short timeout kills slow queries before they hurt cluster performance for others. In the Python tool, you can add row limits to the results. This stops the tool from sending thousands of rows back to the model. Even with these steps, teams still need row-level checks and field masking in flight.
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
Can the OpenAI Agents SDK talk to CockroachDB out of the box?
The SDK does not include a built-in database client of its own. You wrap a standard PostgreSQL driver inside a custom Python tool function. The agent calls that function whenever it needs to run a SQL query.
Why is a read-only database role not enough for AI agents?
A read-only role stops data changes, but it still returns all matching rows. Sensitive fields like emails, card numbers, and phone numbers still reach the model. It also fails to tie database queries back to the original human user.
How do I stop an agent from overloading my CockroachDB cluster?
You should set a strict statement timeout on the agent database role. You should also cap the number of rows your Python tool returns. This keeps bad queries from eating up cluster memory and model tokens.
Related guides
In this post