How to Configure Mastra Bigquery Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a mastra bigquery sandbox by linking an agent tool to a cloud project. You pass a service account key or workload identity so the agent can run queries. Teams often start by giving the agent a broad viewer role to move fast. Broad roles let the agent read every table in the project without limits. If a prompt goes wrong, the agent can pull sensitive rows into memory. How a mastra bigquery sandbox setup works Mastra lets you build AI agents that call external tools during a task. Yo

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 mastra bigquery sandbox by linking an agent tool to a cloud project. You pass a service account key or workload identity so the agent can run queries. Teams often start by giving the agent a broad viewer role to move fast. Broad roles let the agent read every table in the project without limits. If a prompt goes wrong, the agent can pull sensitive rows into memory.

How a mastra bigquery sandbox setup works

Mastra lets you build AI agents that call external tools during a task. You define a custom tool in your app code to talk to Google Cloud. That tool uses the standard BigQuery client library to send SQL statements. A BigQuery sandbox gives you a free test space with storage and query limits. It does not require a billing account to start testing your agent logic.

Next, you create a Google Cloud service account for the agent to use. You grant this account a role that allows running jobs and reading datasets. Your app loads the account credentials from a local file or secret store. When a user asks a question, the agent picks the right tool. It writes a SQL query and sends it to the cloud project. BigQuery runs the job and returns the rows back to your agent.

What native roles solve and what they miss

Cloud IAM roles verify who can log in and which datasets they can touch. The sandbox limits also stop runaway storage costs by setting strict quotas. Together, these native controls build a solid wall around your test project. You can block the agent from dropping tables or reading production datasets.

Still, native cloud roles do not check individual SQL queries in flight. Once the agent logs in, it can read every column inside an allowed table. If a test table holds real emails or card numbers, the agent gets them. The cloud role cannot mask phone numbers or national IDs before rows return. Also, shared service keys make it hard to see which user triggered a query. Teams need a way to inspect commands and rewrite sensitive fields in results.

BigQuery IAM + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Best practices for safer agent testing

Start by scoping the service account to a single dataset instead of the project. Keep real customer data out of your test tables whenever you can. If you must use real data shapes, scrub emails and phone numbers first. Set query size limits in your tool code so bad joins fail fast. Review your cloud audit logs each week to spot odd agent queries.

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

Does the BigQuery sandbox need a credit card?

No, the sandbox lets you run queries and test agents without adding billing info. It applies strict limits on storage size and daily query processing volume.

How should I scope roles for an AI agent?

Give the service account job user permissions at the project level only. Grant data viewer permissions on the single dataset the agent needs to read.

How can I protect PII during agent tests?

Native roles return whole rows once a table check passes. To hide emails or card numbers, use data masking that rewrites matched fields in results.

The query runs. The emails stay hidden.