How to Configure OpenHands MySQL Sandbox

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openhands mysql sandbox by running the agent container alongside an isolated database instance. You then pass database login keys to the agent workspace so it can run queries. Engineering teams use this setup to let AI coding agents test schema changes and fix bugs. Many teams start by giving the agent a root database role to avoid permission errors. Broad database roles create big risks when an AI agent writes and runs SQL on its own. A bad prompt or agent loop can wipe test tabl

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 an openhands mysql sandbox by running the agent container alongside an isolated database instance. You then pass database login keys to the agent workspace so it can run queries.

Engineering teams use this setup to let AI coding agents test schema changes and fix bugs. Many teams start by giving the agent a root database role to avoid permission errors. Broad database roles create big risks when an AI agent writes and runs SQL on its own. A bad prompt or agent loop can wipe test tables or leak sensitive user rows.

How the openhands mysql sandbox architecture works

OpenHands runs tasks inside a dedicated container workspace. This workspace holds the code files, shell tools, and database client libraries. When the agent needs to check data, it opens a shell session inside this container. It reads the database host, user, and password from its local workspace settings.

The MySQL sandbox sits in a separate container on the same virtual network. You link the two containers so the agent can reach the database port. Next, you create a dedicated MySQL user account for the agent. You grant this account permissions on a specific test schema rather than the whole server.

During a coding task, the agent writes SQL queries to test its new code. It sends these queries over the local network to the MySQL server. The database checks the user role, runs the statement, and returns the result rows.

What native database roles solve and what they miss

Native MySQL roles do a good job of blocking access to other databases on the server. You can restrict the agent user to one schema and block admin commands. You can also limit the user to read and write actions on specific tables. This setup stops the agent from dropping the entire database instance by mistake.

Still, static database roles only check who logs in at the start of a session. They do not inspect what individual SQL statements do while the agent works. If an agent needs write access to test an app, it can also delete every row. A shared sandbox with realistic test data creates even more risk for your team.

MySQL Access Governance + AI Sandbox Environments: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Test databases often hold real emails, phone numbers, card numbers, or national IDs from old snapshots. Native MySQL roles return all matched rows in plain text to the agent workspace. The agent then sends those raw results to the external model provider as context. Standard database logs also fail to link a bad query back to a specific agent task. Teams need a way to check queries in flight and rewrite sensitive fields in results.

Best practices for safer agent database testing

Start by keeping your sandbox data clean and small. Seed the database with fake records instead of copying production snapshots into the test container. This step lowers the risk of sending real phone numbers or card numbers to external models.

Separate your database roles by task type whenever you can. Give bug triage agents a read-only MySQL user role. Only grant write permissions when the agent task requires schema migrations or data updates. Tear down and rebuild the database container after each agent run to keep tests clean.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL. It runs next to MySQL, RDS, or Aurora and reads the MySQL wire protocol.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails. When a rule refuses a query, MySQL returns a native error packet with your message. On the response path, hoop.dev data masking rewrites string values in returned rows that match your rules. Every query and decision is logged per resource. See the MIT-licensed project on GitHub.

Frequently asked questions

Should I give OpenHands root permissions in a local MySQL sandbox?

No, you should create a limited MySQL user for the agent. Root roles let the agent change server settings or wipe schemas needed by other tests. Grant only the exact table permissions required for the current coding task.

How do I stop the agent from leaking test data to model providers?

Do not load real customer snapshots into your MySQL sandbox. Use synthetic data generators to build safe test rows. You can also use data masking to rewrite emails and card numbers in query results.

Can multiple OpenHands agents share the same MySQL sandbox?

Sharing one sandbox across multiple active agents causes lock conflicts and broken tests. One agent might alter a table while another agent reads from it. Give each agent workspace its own isolated database schema or container instance.

The query runs. The emails stay hidden.