How to Configure OpenHands Neon Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openhands neon least privilege by creating a custom database role with read-only rules. Then you pass that restricted string to the agent container instead of the admin key. Most teams start by giving their AI coding agent the default project owner role. That shortcut lets an automated agent drop tables, change schemas, or read private user data. A scoped setup stops the agent from touching tables it does not need for its task. How openhands neon least privilege works in practice O

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 neon least privilege by creating a custom database role with read-only rules. Then you pass that restricted string to the agent container instead of the admin key. Most teams start by giving their AI coding agent the default project owner role. That shortcut lets an automated agent drop tables, change schemas, or read private user data. A scoped setup stops the agent from touching tables it does not need for its task.

How openhands neon least privilege works in practice

OpenHands runs as an autonomous coding agent inside an isolated container or local runtime. It writes code, runs shell commands, and queries databases to fix bugs or build features. Neon provides serverless Postgres with instant database branching and standard role-based access rules. When you pair them, you must limit what the agent can do inside the database.

First, you create a dedicated Postgres role inside your Neon project for the AI agent. You revoke default create rights on the public schema for this new role. Next, you grant select rights only on the specific tables the agent needs to read. If the agent must test migrations, you create an isolated Neon branch for that run.

Database branches copy the schema and data without putting the main production branch at risk. You give the agent write rights only on that disposable branch. You then pass the branch string into the agent runtime as a secret variable. The agent logs in with that scoped role and runs its test scripts safely.

What native database roles solve and what they miss

Native Postgres roles and Neon branches solve the basic problem of broad account rights. They stop the agent from deleting production tables or altering core database settings. Branching also keeps test writes away from live customer records during coding sessions. These native controls decide which database role can log in and which tables it touches.

Still, static database roles cannot inspect what individual queries do once the session starts. If the agent needs to read a users table, it gets every column inside by default. The database sends back raw emails, phone numbers, card numbers, and national IDs in results. That raw data flows straight into the agent logs and the language model prompt.

Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static roles also require you to put a plain database password inside the agent container. Since OpenHands can run shell commands, a bad prompt can read that local secret. Also, native roles cannot pause a dangerous query on a shared branch to ask a human. Teams need a way to inspect queries and mask sensitive fields in flight.

Steps to harden agent database sessions

Start by separating schema tasks from data debugging tasks in your daily agent workflows. For code changes, point the agent at a fresh Neon branch with mock data. Never copy live customer rows into a branch where an agent has full write rights. Keep the branch lifetime short and delete it as soon as the pull request closes.

When an agent must query real data to debug an issue, use strict read rules. Grant access only to the exact columns needed for the bug report when possible. Set a short statement timeout on the agent role so bad queries do not lock tables. Finally, review your database logs often to see which queries the agent runs during tasks.

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

Why should OpenHands not use the default Neon owner role?

The default owner role can drop tables, change schemas, and read all sensitive records. If the agent makes a mistake, it can break your live database in seconds.

Do Neon branches protect private customer data from AI agents?

A standard branch copies all data from the parent branch, including private user records. Unless you scrub the branch or mask results, the agent still reads real customer data.

How can teams protect emails and card numbers during agent queries?

Teams can use column grants in Postgres or apply data masking to query results. Masking rewrites matched fields like emails and card numbers before the agent reads the output.

The query runs. The emails stay hidden.