How to Configure OpenHands Postgres Guardrails
You set up openhands postgres guardrails by creating strict database roles with limited read permissions. Next, you revoke default public access and restrict which columns the AI agent can read. Engineering teams often give coding agents broad database credentials to speed up bug fixes. This mistake lets an autonomous agent drop tables or read private user data by accident. A safe setup limits what the agent can touch before it runs a single query. How native openhands postgres guardrails work
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 openhands postgres guardrails by creating strict database roles with limited read permissions. Next, you revoke default public access and restrict which columns the AI agent can read. Engineering teams often give coding agents broad database credentials to speed up bug fixes. This mistake lets an autonomous agent drop tables or read private user data by accident. A safe setup limits what the agent can touch before it runs a single query.
How native openhands postgres guardrails work
PostgreSQL controls access through roles and object privileges. When an OpenHands agent connects to a database, it logs in with a specific role. Teams can set up group roles to manage permissions for multiple users and agents. You then grant the agent role membership in a restricted group role. This keeps permission management clean as your team adds more automated tools.
To keep the agent from changing data, you grant only the select privilege. In PostgreSQL, the select privilege lets a role read from a table or view. You can also grant select on specific columns instead of the whole table. This helps when a table holds both safe app data and secret fields. Still, you must remember that the select privilege also allows the copy to command. An agent with select rights can still export rows from the allowed columns.
You also need to lock down the special role named public. Every role on the system inherits privileges granted to public. By default, public gets permission to connect to databases and create temporary tables. It also gets permission to run functions and procedures. The database owner can revoke these default permissions from public to tighten security. In PostgreSQL 15 and later, default settings block users from creating objects in the public schema. If you run an older version or an upgraded database, you must revoke create rights on the public schema from public yourself.
What native roles solve and what they miss
Native database roles are great for stopping basic mistakes. A read-only role stops an OpenHands agent from deleting rows or altering table schemas. Revoking public execution rights stops the agent from running dangerous stored procedures. Column grants let you block access to specific columns that you already know are sensitive.
AI Guardrails + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static database roles leave big operational gaps in real life. Database permissions only check who logs in and which objects they touch. They do not inspect what individual queries do in flight. First, column grants require you to maintain long permission lists across every schema change. If a developer adds a new table with customer emails or phone numbers, someone must update the grants right away. Also, unstructured text fields or JSON columns often mix safe text with card numbers or national IDs. Native column grants cannot rewrite matched fields in results when secret data sits inside a text block.
Second, the agent needs a way to log in. In standard setups, someone puts a database username and password into the agent workspace. Because the agent can run shell commands and read local files, it can read those stored credentials. Third, a valid read-only role can still run a bad query that scans millions of rows. That single query can lock up memory and slow down the database for real users. Native roles cannot pause a risky query to ask a human for approval first.
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 native PostgreSQL roles hide sensitive data inside JSON columns?
No, native select privileges only work at the table or column level. They cannot inspect inside a JSON column to rewrite emails, phone numbers, or card numbers in query results.
Why can my read-only OpenHands agent still create objects in the database?
Your database might have old default privileges active on the public role. You must revoke create rights on the public schema and revoke temporary table rights from public.
Does the PostgreSQL select privilege allow bulk data exports?
Yes, granting the select privilege on a table or column also allows the copy to command. An agent can use this command to export all readable rows at once.
Related guides
In this post