How to Configure OpenHands Postgres Permissions
You set up openhands postgres permissions by making a dedicated database role with read-only grants. Then you give that role to the AI agent workspace so it can run queries. Most engineering teams start by sharing a dev database password with the agent. When permissions are too broad, a bad query from the agent can drop tables or leak user data. How openhands postgres permissions work in practice OpenHands runs tasks inside a sandbox container that acts like a human developer. When the agent
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 permissions by making a dedicated database role with read-only grants. Then you give that role to the AI agent workspace so it can run queries. Most engineering teams start by sharing a dev database password with the agent. When permissions are too broad, a bad query from the agent can drop tables or leak user data.
How openhands postgres permissions work in practice
OpenHands runs tasks inside a sandbox container that acts like a human developer. When the agent needs to check data, it uses the database credentials in its workspace. Postgres checks the role tied to those credentials before it runs any query. If you use a shared admin role, the agent gets full control over every table.
A safer path is to build a group role for your AI agents. Postgres lets you set up group roles to manage rules when you have many users. You then grant each agent role membership in that group role. This keeps your rule list clean as your team adds more bots.
For read access, you grant the SELECT privilege to the agent role. In Postgres, SELECT lets a role read from a whole table or view. You can also grant SELECT on specific columns of a table or materialized view. Keep in mind that SELECT also allows the role to run COPY TO commands. That means an agent with table read rights can export rows to a file.
Locking down default grants and schema rules
Creating a new role is only the first step. Every new role in Postgres inherits rights from a special role named PUBLIC. Anything granted to PUBLIC applies to every role on the system. By default, PUBLIC gets CONNECT and TEMPORARY rights on databases. It also gets EXECUTE rights on functions and procedures.
The database owner can revoke these default grants from PUBLIC at any time. If you do not revoke them, your AI agent might run stored procedures by mistake. It could also build temporary tables that eat up disk space during a loop.
You also need to check write rules on your default schema. In Postgres 15 and newer, the default setup blocks regular users from creating objects in the public schema. Older versions, or databases upgraded from them, still allow this by default. On those older systems, an admin must revoke CREATE on the public schema from PUBLIC. Doing this stops the agent from leaving junk tables behind after a coding session.
AI Agent Permissions + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles leave open
Native database roles do a good job of deciding who can log in. They also control which tables or columns a role can read or change. Still, static grants cannot inspect what an individual query does while it runs in flight.
For example, an agent often needs to read a customer table to fix a bug. Even with column grants, the agent might need to see email or phone number fields to test a feature. Native grants return the raw text for every row the query matches by default. Static roles cannot rewrite emails, phone numbers, card numbers, or national IDs in the query results.
Static roles also lack approval checks for risky commands. Sometimes an agent needs write access to run a schema update or fix broken rows. If you grant write rights to the role, the agent can run any update right away. Native Postgres permissions cannot pause a single statement and wait for a human to approve it. They also require you to put real database passwords inside the agent workspace.
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 restrict an OpenHands agent to read only certain columns in Postgres?
Yes, Postgres lets you grant the SELECT privilege on specific columns of a table or view. The agent role will get a permission error if it queries any other column on that table.
Why can my new read-only agent role still run functions in Postgres?
Postgres grants EXECUTE on functions and procedures to the special PUBLIC role by default. Since every role inherits from PUBLIC, the object owner must revoke EXECUTE from PUBLIC to stop the agent.
How do I stop an AI agent from creating tables in the public schema?
Postgres 15 and later block this by default for new databases. On older versions or upgraded databases, an admin must revoke the CREATE privilege on the public schema from PUBLIC.
Related guides
In this post