How to Configure OpenAI Agents SDK Bigquery Sandbox
You set up an openai agents sdk bigquery sandbox by linking a custom tool function to a restricted cloud role. Next, you point the agent tool at a test dataset with read-only permissions. Many engineering teams start by giving the agent a broad service key for fast testing. That wide role lets an agent read private tables or run expensive scans by mistake. How the openai agents sdk bigquery sandbox workflow runs The agent framework uses Python functions as tools that the model can call during
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 bigquery sandbox by linking a custom tool function to a restricted cloud role. Next, you point the agent tool at a test dataset with read-only permissions. Many engineering teams start by giving the agent a broad service key for fast testing. That wide role lets an agent read private tables or run expensive scans by mistake.
How the openai agents sdk bigquery sandbox workflow runs
The agent framework uses Python functions as tools that the model can call during a run. You write a short wrapper function that takes a text query from the model. Inside that function, the standard cloud client library sends the SQL statement to the warehouse. The warehouse runs the job and returns the rows back to your Python app.
To keep this setup in a safe test space, you create a separate project or dataset first. You then make a dedicated cloud service account just for the agent app. You grant that account permissions to run jobs and read tables only inside the test dataset. You do not attach project-wide editor or owner roles to this account.
When the agent receives a user prompt, it picks the database tool and writes a SQL query. The Python function uses the scoped service account key to log in and run the query. If the model tries to query a table outside the test dataset, the cloud platform blocks it. The agent then gets the allowed rows and writes a final answer for the user.
What native roles solve and what they miss
Cloud roles and separate test datasets do a good job of controlling who can log in. They also draw a hard line around which datasets the agent service account can reach. If a prompt tricks the model into dropping a production table, the read-only role stops the drop. Native cloud controls also let you set basic byte limits so one bad query does not blow up costs.
Still, static cloud roles only check permissions at the dataset or table level before the query runs. They do not inspect what each statement does in flight or check who asked the agent. Every user who talks to the agent shares the exact same service account identity in the warehouse logs. When a strange query runs, your audit logs only show the shared bot account, not the human user.
BigQuery IAM + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native dataset permissions also return every column inside an allowed table by default. If your test data holds real emails, phone numbers, card numbers, or national IDs, the query pulls them. Those raw fields flow straight into the model prompt context and external API logs. Dynamic data masking fixes this by rewriting matched fields in results before the agent reads the rows.
Keeping agent database tools safe in daily work
Teams that run database agents in daily work need controls that act on each query in real time. First, keep the service account strictly read-only so the model cannot alter table data or schemas. Second, load synthetic data or scrub sensitive columns before copying production tables into the test space. Third, log the full text of every generated SQL statement along with the human user identity.
You should also add a review step when an agent needs to run a high-cost or sensitive query. A human reviewer can check the generated SQL statement before the database actually runs it. Combining scoped cloud roles with query-level checks gives your team a safe way to test agent workflows.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
How does the agent framework connect to the cloud warehouse?
The framework does not ship a built-in database client of its own. Instead, you wrap the standard cloud Python client inside a custom function tool for the agent.
Why is a read-only role not enough for a test dataset?
A read-only role stops data changes, but it still lets the agent read every row and column by default. If test tables contain real emails or card numbers, those values get sent to the model provider.
How can teams stop an agent from running huge queries?
You can set a maximum bytes billed limit on each query job inside the Python client wrapper. If a generated SQL query tries to scan too much data, the warehouse cancels the job right away.
Related guides
In this post