How to Configure OpenHands Postgres Connect
To set up openhands postgres connect, create a dedicated database role with scoped read rights. Then pass those login details into the agent workspace so it can run queries. Many teams start by giving the coding agent a shared admin account to save time. This broad access lets an automated agent alter tables or read sensitive customer columns. How openhands postgres connect works with database roles OpenHands runs tasks inside a sandbox workspace where it can write code and run tools. When th
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 openhands postgres connect, create a dedicated database role with scoped read rights. Then pass those login details into the agent workspace so it can run queries. Many teams start by giving the coding agent a shared admin account to save time. This broad access lets an automated agent alter tables or read sensitive customer columns.
How openhands postgres connect works with database roles
OpenHands runs tasks inside a sandbox workspace where it can write code and run tools. When the agent needs database context, it uses standard client libraries to open a session. The database checks who the agent is based on the role name and password provided.
A safe setup starts inside PostgreSQL by building a dedicated group role for agents. Admins set up group roles to manage privileges when many users or tools need access. You then create a specific login user for the agent and add it to that group.
Next, you must check what the special PUBLIC role allows inside your database instance. By default, PUBLIC gives every role connect and temporary table rights on the database. It also grants execute rights on functions and procedures to every user on the system. Database owners can revoke these default grants so the agent starts with zero hidden rights.
You should also check schema creation rules before the agent runs its first task. In PostgreSQL 15 and later, regular users cannot create objects in the public schema by default. Older databases, or instances upgraded from earlier versions, still let PUBLIC create new objects there. On those older systems, an admin must revoke create rights on the public schema from PUBLIC.
Once the base role is clean, you grant read rights only where the agent needs them. The select privilege allows reading from an entire table, view, or materialized view. You can also grant select on specific columns of a table to keep private fields off limits. Keep in mind that the select privilege also allows exporting rows through the copy command.
Why static database roles are not enough for AI agents
Native database roles do a good job of deciding which user can log in. They also lock down which tables or columns a role is allowed to read. This stops an agent from dropping a production table if it only holds read privileges.
End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static grants do not check what individual queries do while the session is active. If an agent has select rights on a customer table, it can still pull every row. If a column holds emails, phone numbers, card numbers, or national IDs, the query returns them. Column grants are all-or-nothing, which makes it hard when agents need to inspect table shapes.
Credentials also sit inside the agent workspace when you rely only on direct database logins. Anyone or any process that reads the agent workspace variables can copy that database password. Native roles also do not tie an individual SQL statement back to the specific developer prompt. Teams need a way to inspect queries in flight and rewrite sensitive fields in results.
Steps to keep agent database sessions safe
Start by removing shared admin accounts from all automated coding tools and agent workspaces. Create a separate database user for each agent workflow and assign it to a read group. Revoke default execute and temporary table grants from the PUBLIC role on target databases.
Grant select rights only on the specific tables and columns required for the current coding task. Rotate the agent password often so old credentials do not linger in test workspaces. Review database logs each week to see which tables the agent queries most often.
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 an OpenHands agent to read only specific columns in PostgreSQL?
Yes, PostgreSQL lets you grant the select privilege on specific columns of a table or view. The agent can then query those allowed columns without having read rights on restricted columns.
Why can my read-only agent still create objects 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 from PUBLIC on that schema to stop it.
What default rights does every new PostgreSQL role get automatically?
Every new role inherits privileges granted to the special PUBLIC role by default. This includes database connect rights, temporary table creation, and execute rights on functions and procedures.
Related guides
In this post