How to Configure Goose Postgres Sandbox
To set up a goose postgres sandbox, give your agent a restricted database role. Next, point the agent session to an isolated test database with limited schema rights. Teams often start by handing an AI tool a broad developer account. That shortcut lets the agent drop tables or read sensitive rows by mistake. A strict setup keeps automated queries inside safe boundaries from day one. How a goose postgres sandbox works with native roles A safe setup starts inside the database engine itself. You
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.
To set up a goose postgres sandbox, give your agent a restricted database role. Next, point the agent session to an isolated test database with limited schema rights. Teams often start by handing an AI tool a broad developer account. That shortcut lets the agent drop tables or read sensitive rows by mistake. A strict setup keeps automated queries inside safe boundaries from day one.
How a goose postgres sandbox works with native roles
A safe setup starts inside the database engine itself. You create a dedicated group role for the agent and its tasks. Then you grant your agent user membership in that group role. This keeps permission updates simple as your team adds more automated tools.
Next, you lock down what the public role can do. By default, the special public role gets connect and temporary table rights on databases. It also gets execute rights on functions and procedures. The database owner can revoke these default grants to tighten the sandbox.
In PostgreSQL 15 and later, new databases stop all users from creating public schema objects. Older databases or upgraded systems might still allow this broad create right. In those cases, an admin must revoke create on the public schema from public. This stops the agent from building rogue tables in shared spaces.
After you remove broad defaults, you grant read rights where needed. In PostgreSQL, the select privilege lets a role read from tables, views, or materialized views. You can even grant select on specific columns instead of the whole table. Keep in mind that the select privilege also allows copy to operations.
Why database roles alone leave runtime gaps
Native database roles solve the first part of sandbox security. They decide which user can log in and which objects that user can touch. Group roles and column grants stop an agent from reading restricted tables or writing bad data.
Still, static database grants do not watch what happens inside an active session. Once the agent logs in, the database accepts any valid query that matches the role. A static role cannot pause a risky command to ask a human for approval. It also cannot rewrite sensitive text inside the rows that a permitted query returns.
AI Sandbox Environments + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
For example, an agent may need to read a customer table to fix a bug. Even with column grants, test tables often hold real emails, phone numbers, or card numbers. If the role has select rights on those columns, the query returns the raw values. Data masking solves this by rewriting matched fields like national IDs in query results.
Static credentials also create key management work for the engineering team. Someone has to store the database password on the machine where the agent runs. If that local file leaks, anyone can use those same sandbox rights.
Managing schema changes and default rights in the sandbox
A test database changes often as developers run migrations and test new features. When a user creates a new table, existing roles do not get automatic access. Admins must set up default privileges so the sandbox role can read new test objects. Those default rules apply only to objects created by the specific target role you name.
If different developers run migrations, each developer role needs matching default privilege rules. Without this step, the agent hits permission errors right after a schema update. Teams then get tempted to grant superuser rights just to make the errors stop. Keeping a clean group role structure prevents that drift and keeps the sandbox tight.
Add query and result controls beside Postgres
Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.
When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.
Frequently asked questions
Can I limit the agent to specific columns in a table?
Yes, PostgreSQL lets you grant the select privilege on specific columns of a table or view. The agent can then query only the permitted columns and gets an error on others.
Why can my sandbox user still create tables in the public schema?
Databases created before PostgreSQL 15 allow the public role to create objects in the public schema. An admin must revoke the create privilege on the public schema from the public role.
What default rights does every new database role get in PostgreSQL?
Every role inherits privileges granted to the special public role. By default, this includes connect and temporary table rights on databases, plus execute rights on functions.
Related guides
In this post