How to Configure Pydantic AI DynamoDB Sandbox
You set up a pydantic ai dynamodb sandbox by pairing agent tools with an isolated database. Next, you assign a narrow cloud role that limits what the agent can read or write. Teams often start by giving the agent broad permissions to speed up early testing. This shortcut creates risk when the agent runs bad queries or reads sensitive items. A good sandbox keeps the agent inside safe bounds from day one. How a pydantic ai dynamodb sandbox works Pydantic AI lets engineers build agents that use
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 a pydantic ai dynamodb sandbox by pairing agent tools with an isolated database. Next, you assign a narrow cloud role that limits what the agent can read or write. Teams often start by giving the agent broad permissions to speed up early testing. This shortcut creates risk when the agent runs bad queries or reads sensitive items. A good sandbox keeps the agent inside safe bounds from day one.
How a pydantic ai dynamodb sandbox works
Pydantic AI lets engineers build agents that use structured inputs and outputs. You define tools as plain Python functions with strict type hints. The framework checks every tool argument against your schema before the function runs. For database work, you pass a cloud client into the agent through its dependency system. This setup keeps your database session logic clean and separate from your prompt logic.
On the database side, a DynamoDB sandbox gives your team a safe place to test. Teams either run a local database container or spin up a separate cloud account. The agent uses an assigned IAM role to log in with DynamoDB tables in that test space. You attach a policy to that role that lists allowed actions like reading or writing items. When the agent calls a tool, the function sends the request using that role.
Scoping permissions and test data
A strong sandbox starts with a tight IAM role for your agent. Never give the agent wildcard permissions across all tables in your account. Instead, write a rule that names the exact sandbox table resource. If the agent only answers questions, give the role read permissions only. If the agent updates state, allow item writes but block table deletion and schema changes.
You must also watch the data you load into your test tables. Many teams copy real records into the sandbox to make tests look real. If you do this, the agent will read real emails, phone numbers, and card numbers. Those sensitive values then flow straight into the external model provider logs. Always fill your sandbox tables with fake data or scrub fields before loading them.
AI Sandbox Environments + DynamoDB Fine-Grained Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where native sandbox controls fall short
Cloud roles and type checks solve only part of the agent safety problem. Pydantic AI checks that tool inputs match the right data types and shapes. Cloud IAM checks which role is allowed to log in with DynamoDB tables. Neither layer looks at the actual items or queries moving in flight.
Once a role has permission to read a table, it can read every attribute inside. If a table holds mixed data, the agent pulls back sensitive fields along with safe ones. A valid tool call can also run a full table scan or overwrite the wrong item key. Native cloud logs record the API call, but they do not link it to the user prompt. Teams need a way to inspect commands, mask fields, and approve risky writes at runtime.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
How do I keep a Pydantic AI agent from deleting sandbox tables?
Assign a dedicated IAM role to the agent workload. Write a permission rule that allows item reads and writes, and explicitly deny table deletion actions.
Should we use a local container or a cloud account for the DynamoDB sandbox?
Use a local database container for fast unit tests on a developer laptop. Use a separate cloud account when you need to test real IAM roles and network rules.
How can we stop real customer data from reaching the model during sandbox tests?
Generate synthetic records for your test tables instead of copying production data. You can also use data masking to rewrite emails, phone numbers, and card numbers in query results.
Related guides
In this post