How to develop with AI Safely
November 16, 2026 • 10 min read • Intermediate

In July 2025, Replit's coding agent deleted SaaStr's production database during a code freeze. It had been told, in capitals, to make no more changes without permission. It then told founder Jason Lemkin that rollback was impossible. Thankfully It wasn't, and he recovered the data.
The agent wasn't malicious or bad, it was simply trying to achieve it's goal it had been told to do. Ask one to update a database schema and it may decide the easiest way is to drop the table and recreate it.
So how do we build with AI safely? How do we prevent it running and successfully executing destructive commands?
There are three common options:
- Ask nicely in instruction files.
- Check tool calls with hooks.
- Sandbox the agent completely.
It's best to use them all in a layered approach.

Instructions: context files and skills
Effectiveness: low
Context files like CLAUDE.md and AGENTS.md load into every session, so the agent always sees the rules you've set. Skills only load when the agent decides they're relevant, so a rule inside a skill can be missed entirely.
Either way, these are requests and should be treated this way. They will guide the agent in the right direction but will not prevent the agent running destructive commands.
Hooks
Effectiveness: medium
Hooks run your own scripts at set points in the agent's lifecycle. A PreToolUse hook runs before every tool call. In Claude Code you match on the tool name (e.g. Bash), and the script receives the full tool input as JSON. It can then inspect the command and block it.
1#!/bin/bash
2cmd=$(jq -r '.tool_input.command')
3if echo "$cmd" | grep -qiE 'drop (table|database)|rm -rf'; then
4 echo "Blocked: destructive command" >&2
5 exit 2 # exit code 2 blocks the call
6fiThe hook itself works really well and runs every time. But what fails is the denylist inside it.
I once watched an agent get blocked by a guard script, then write the same command into a file and run it, bypassing the guard. The write went through a different tool, so the hook never saw it and it ran the script.
Worth noting you can use allowlists with hooks instead of denylists which allows you to explicitly control what tools can be run instead of denying what can't.
Still, the agents can get around hooks, so they should be used as a mid level tier of defence.
Sandboxes
Effectiveness: very high
A sandbox runs the agent in an isolated environment, so even if it runs something destructive, it can't really do much (unless you specifically give it access). Docker Sandboxes (the sbx CLI) gives each agent its own microVM with its own kernel, filesystem, Docker engine and network.
The basic setup is simple: sbx run claude. The more useful workflows takes a little more work.
When I asked an agent whether it could escape its sandbox, it hit a cybersecurity guardrail and refused to help. That was reassuring, but the sandbox boundary is actually what protects you. This means escaping it would take a hypervisor vulnerability.
Stores secrets outside the sandbox
You store a key with sbx, such as a GitHub token. When the agent makes a request to GitHub, a proxy on your machine adds the key with the request. The agent can use the GitHub API but never sees the key. In fact if you try to see the key gho_sbxproxymanaged000000000000000000000 this is what shows from within the sandbox.

The Network is controlled by you
On first run you pick a preset: Open (everything except private network ranges), Balanced (common development services) or Locked Down (nothing unless you allow it). You can allow a new host by running sbx policy allow network api.example.com.
You can also bring in skills and MCP servers, and run the same sandboxes in the cloud.
A watch out
A sandbox only protects what the agent can't reach. If you give your agent in the sandbox direct access to your DB with your credentials you could still have similar issues as if you weren't running in a sandbox.
Giving the agent external access from the sandbox
I recently needed a sandboxed agent to use a CLI on my machine. I wanted it limited to specific commands, and kept away from the secrets the CLI runs with.
The solution was to put those commands behind a local MCP server and open only that port to the sandbox. This meant I was able to control exactly the commands the agent had access to but also that the agent had more information via MCP tools to know when to use each of the CLI commands. Otherwise I would have needed to write a skill on how to use the CLI for the agent.
The same pattern works for read-only database queries, specific scripts or automations on your machine. The MCP server can act as your security boundary, so it's worth building it like one. I would recommend:
- Typed parameters, never use a direct shell string.
- A read only database role.
- Only expose the port you actually need for the MCP server.

Disaster Recovery
None of this replaces backups. Keep them where the agent's credentials can't reach, and test that you can restore them. Kent C. Dodds runs disaster recovery drills in his AI platform Kody.
Checklist
- Put your rules in CLAUDE.md or AGENTS.md.
- Use hooks with allowlists.
- Run agents in a sandbox with a locked-down network policy.
- Keep secrets outside the sandbox and keep production credentials out of reach.
- Give host access through narrow MCP tools.
- Test your backups/ run disaster recovery drills.
I hope this article helps you create safe workflows for personal use or at work. Agents are amazing, but it's up to us as developers to ensure we are taking reasonable steps to safeguard customer data and not expose the businesses we work for to unnecessary risks.
Thanks!
Rupert
