How to Configure OpenAI Agents SDK ClickHouse Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openai agents sdk clickhouse sandbox by creating a limited database user. Then you bind that user to your agent tool functions. Engineering teams often start by giving an agent a broad admin login. That approach makes early testing fast for the team. Still, broad permissions create huge risks when an agent runs generated queries. A single bad prompt can read private tables or drop production data. Building a strict sandbox keeps your analytical data safe during agent runs. How to

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 an openai agents sdk clickhouse sandbox by creating a limited database user. Then you bind that user to your agent tool functions. Engineering teams often start by giving an agent a broad admin login. That approach makes early testing fast for the team. Still, broad permissions create huge risks when an agent runs generated queries. A single bad prompt can read private tables or drop production data. Building a strict sandbox keeps your analytical data safe during agent runs.

How to set up an openai agents sdk clickhouse sandbox

Your first step happens inside the ClickHouse database itself. ClickHouse manages users, roles, row policies, settings profiles, and quotas as access entities. You can create and manage all of these entities with SQL. To turn on SQL-driven access control, you set a storage directory on the server. You also need at least one user with access management rights turned on. Once you enable that, you can create a dedicated user for your agent.

Creating a user requires the create user privilege in ClickHouse. Remember that a user can only grant privileges that they hold themselves. In your create statement, you set the login method for the agent. You also limit the specific hosts that the agent user can log in from. Next, you assign default roles and per-user settings to cap resource usage. This forms the base of your openai agents sdk clickhouse sandbox.

After creating the user, you must lock down what tables it can read. ClickHouse lets you grant select rights on specific columns in a table. If you grant select on two columns, the agent can query only those columns. Queries asking for other columns will fail right away. A select all query is also refused and returns no data at all. That rule holds unless the table has only the granted columns. You can also use a trailing asterisk to grant select by table name prefix. Finally, your Python code passes this limited user to the agent tool function.

What native database roles solve and what they miss

Native ClickHouse access controls solve the initial login and table boundary problem. Host limits make sure the agent only logs in from your app servers. Column grants stop the agent from reading secret columns that you excluded. Quotas and settings profiles stop a bad query from using all your memory. These built-in tools give you a strong baseline for your database setup.

Still, static database roles only decide who can log in to the cluster. They do not inspect what individual queries do while in flight. An agent needs read access to user tables to answer support questions. Once a column is granted, the database returns every row in that column. If an allowed column holds emails, phone numbers, or card numbers, the agent gets them. Native grants cannot rewrite matched fields in results before the agent reads them.

ClickHouse Access Management + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static credentials also create a secret sprawl problem for your team. You have to store the database password inside your agent runtime environment. If you run ten different agents, you must manage ten sets of keys. Also, database logs only show the shared agent user name. They do not link a specific SQL query back to the human user or prompt. When an agent runs a bad query, you cannot trace the root cause.

Why runtime query controls matter for AI agents

AI agents do not behave like normal backend apps with fixed queries. An agent writes fresh SQL on the fly based on user input. Even with a read-only role, a model can join allowed columns in risky ways. It can pull bulk national IDs or emails into the model context window. From there, sensitive data can leak into third-party model logs or chat history.

To fix this gap, teams pair native database roles with runtime controls. You still keep your strict ClickHouse user and column grants in place. On top of that, you check each query before it hits the database. You also apply data masking to rewrite sensitive fields in the query results. This approach keeps raw secrets out of prompts while letting the agent work.

Check ClickHouse queries and results before execution

Access control in ClickHouse is essential setup. Setup alone does not check single queries for risk or rewrite sensitive strings in returned rows. By design, hoop.dev sits beside the server as a sidecar for your ClickHouse and parses every statement before execution.

First, hoop.dev guardrails block disallowed deletes, drops, and alter mutations. Then hoop.dev data masking rewrites sensitive string columns in responses and logs each decision per resource. Read the docs and source on GitHub.

Frequently asked questions

Can an OpenAI agent run select all queries on a restricted ClickHouse table?

No, if you only grant select rights on specific columns in a table. ClickHouse refuses select all queries unless the table contains only the granted columns.

How do I limit where my ClickHouse agent user logs in from?

When you create the user in ClickHouse, you can define allowed client hosts. This rule stops the agent key from working outside your own app servers.

Why are column grants not enough to protect emails and card numbers?

Column grants are all or nothing for each column you expose to the agent. If an agent needs a column for context, it gets the raw text unless masking rewrites matched fields in results.

The query runs. The emails stay hidden.