How to Configure OpenHands MySQL Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openhands mysql least privilege by making a scoped database user for your agent. You then grant that user read or write rights on only the tables it needs. Many teams give coding agents a shared admin key to move fast during setup. That broad key lets an agent drop tables, change schemas, or read private user data. How openhands mysql least privilege works in practice OpenHands runs tasks inside a sandbox container that acts like a developer workspace. When the agent writes or test

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 mysql least privilege by making a scoped database user for your agent. You then grant that user read or write rights on only the tables it needs. Many teams give coding agents a shared admin key to move fast during setup. That broad key lets an agent drop tables, change schemas, or read private user data.

How openhands mysql least privilege works in practice

OpenHands runs tasks inside a sandbox container that acts like a developer workspace. When the agent writes or tests database logic, it reads connection keys from its workspace. It uses those keys to log in to your MySQL server and run queries.

MySQL controls what that session can do through user accounts and privilege grants. Instead of sharing a root account, you create a separate account just for the agent. You lock that account to the IP range of the agent runtime host.

Next, you assign privileges at the database, table, or column level. If the agent only builds reports or debugs bugs, give it read grants on non-sensitive tables. If the agent tests schema migrations, point it at a scratch schema with write rights.

You can also use database roles to group these rules together for your team. Roles let you update table grants in one place when your schema changes over time. You should also set query resource limits on the agent account in MySQL. Resource limits stop a bad loop from running heavy queries that slow down your server.

Scoping schema access for coding agents

A clean schema layout makes database scoping much easier for engineering teams to manage. Many teams split public app tables from private tables that hold billing or user secrets. You can grant the agent account access to the app schema while blocking the secret schema.

When the agent needs to read a mixed table, column grants or views help. A MySQL view can expose safe columns from a table while leaving out sensitive columns. You then grant the agent read access on the view instead of the base table. This setup lets the agent check data shapes without pulling raw secrets into its workspace.

Least Privilege Principle + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native grants solve and where gaps remain

Native MySQL grants do a good job of blocking access to whole tables and schemas. They stop an agent from dropping production databases or writing to read-only tables. They also keep the agent out of system tables that manage database users.

Still, static grants only check who logs in and which objects they can touch. They cannot inspect what an individual SQL query does while it runs in flight. Once an agent has read rights on a customer table, it can select every row.

A broad query can pull emails, phone numbers, card numbers, or national IDs into agent logs. If the agent has update rights to fix a bug, a bad filter can overwrite thousands of rows. Native MySQL roles also require you to place static database passwords inside the agent sandbox. If a prompt flaw tricks the agent, it could print those static keys in its output.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev is an open-source proxy that runs as a sidecar for your MySQL. It reads plain queries, prepared statements, and cursors on the wire.

First, hoop.dev guardrails block banned actions before MySQL runs them. An AI Analyzer you configure can score intent, and hoop.dev data masking rewrites sensitive string columns in results. Every query and verdict goes to the resource audit trail. Find the open-source binary on GitHub.

Frequently asked questions

Should OpenHands use the same MySQL user as my main app?

No, you should always make a separate MySQL account for your coding agent. A dedicated account lets you restrict table grants and track agent queries in your logs.

How do I stop an agent from reading sensitive columns in MySQL?

You can restrict grants to safe columns or create a MySQL view that excludes private fields. You can also use data masking to rewrite emails, phone numbers, or card numbers in results.

Can an agent run schema changes with least privilege?

Yes, give the agent alter and create rights only on a dedicated test or staging schema. Never grant schema change rights to an autonomous agent on a live production database.

The query runs. The emails stay hidden.