How I Built a Zero-Trust Docker Sandbox for AI Coding Agents & Untrusted Repos
Description and use
Create a non‑root Docker sandbox for safely running untrusted code and AI agents, with instant file sync and persistent dependency caching.
Problem
Running untrusted Python code or AI coding agents on a host system risks accidental modification or deletion of host files and permission headaches when containers write files as root.
Outcome
Developers can run untrusted Python code and AI agents in an isolated, non‑root Docker container with instant file sync, zero permission headaches, and persistent dependency caching, all set up in under two minutes.
Workflow
- 1. Build the base Docker image with pre‑created cache directories and open permissions.
- 2. Add the saferun alias to ~/.zshrc or ~/.bashrc.
- 3. Clone any repository locally.
- 4. Open a terminal at the project root and type
saferunto enter the sandbox. - 5. Run untrusted code, install dependencies with
uv, or use OpenCode inside the container. - 6. Exit the container with
exit; the container is removed and all edits remain on the host.
Evidence
I built saferun a zero-trust, disposable Docker sandbox designed specifically for Python developers and AI agent workflows on macOS and Linux.
Files edited inside PyCharm or VS Code on the host machine sync instantly with the container.
- Record date: 2026-09-08T23:16:05.375Z