Tools: Using a Docker Sandbox for a Coding Agent

Tools: Using a Docker Sandbox for a Coding Agent

Source: Dev.to

Scenario ## Step 1: Create a Sandbox ## Step 2: Enter the Sandbox ## Step 3: Run a Coding Agent (Unattended) ## Step 4: Let the Agent Install Dependencies ## Step 5: Let the Agent Use Docker ## Step 6: Review the Results on the Host ## Step 7: Delete the Sandbox ## Why This Pattern Works ## When to Use Docker Sandboxes This guide shows a concrete, end-to-end example of how Docker Sandboxes can be created and used to safely run autonomous coding agents that can install packages, modify files, and even run Docker — without touching your host machine. You want to let a coding agent: …but without risking your laptop or credentials. Docker Sandboxes solve this by running the agent inside a disposable microVM with only your project workspace mounted. Create a new sandbox using your local project directory as the workspace: Start an interactive shell inside the sandbox: You are now inside the sandbox, not your host machine. Inside the sandbox, run your coding agent in permissive mode: This is the intended workflow for Docker Sandboxes. The agent can freely modify the environment: No permission prompts. No approval loops. No risk to your machine. Inside the sandbox, the agent can build and run containers: This capability is what makes Docker Sandboxes fundamentally different from regular containers. Exit the sandbox and inspect the changes: You’ll see only the intentional code changes made by the agent. No stray system packages. No modified OS files. No lingering background processes. When you’re done, delete the sandbox: The microVM is destroyed immediately. Docker Sandboxes give agents: This pattern is ideal when: Agents need freedom. Your machine doesn’t. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK: docker sandbox create --name agent-sandbox --workspace ./my-project Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker sandbox create --name agent-sandbox --workspace ./my-project COMMAND_BLOCK: docker sandbox create --name agent-sandbox --workspace ./my-project COMMAND_BLOCK: docker sandbox exec agent-sandbox bash Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker sandbox exec agent-sandbox bash COMMAND_BLOCK: docker sandbox exec agent-sandbox bash CODE_BLOCK: claude-code run --dangerously-skip-permissions --project /workspace Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: claude-code run --dangerously-skip-permissions --project /workspace CODE_BLOCK: claude-code run --dangerously-skip-permissions --project /workspace COMMAND_BLOCK: apt-get update apt-get install -y nodejs npm Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: apt-get update apt-get install -y nodejs npm COMMAND_BLOCK: apt-get update apt-get install -y nodejs npm COMMAND_BLOCK: docker build -t my-app . docker run -p 8080:8080 my-app Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker build -t my-app . docker run -p 8080:8080 my-app COMMAND_BLOCK: docker build -t my-app . docker run -p 8080:8080 my-app COMMAND_BLOCK: git diff Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker sandbox delete agent-sandbox Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: docker sandbox delete agent-sandbox COMMAND_BLOCK: docker sandbox delete agent-sandbox - Modify a real codebase - Install system dependencies - Build and run containers - Run unattended with permissive flags - Creates a dedicated microVM - Mounts only ./my-project into the sandbox - Keeps your OS, home directory, and secrets isolated - Any package installs - Any config changes - Any Docker commands - The agent runs inside a microVM - Only the project directory is writable - No access to your host OS, SSH keys, or credentials - This does not use your host Docker daemon - Containers run entirely inside the sandbox microVM - The environment is wiped - Nothing persists except your code changes - You start clean the next time - A real operating system - Package managers and system tools - Docker access - Full autonomy - Strong isolation via microVMs - Disposable environments - Zero host contamination - Confidence to use permissive agent modes - Running coding agents unattended - Using flags like --dangerously-skip-permissions - Allowing agents to install tools dynamically - Letting agents build and run containers - Experimenting aggressively without fear