Secure AI Coding Agents: 3-Step Permission Sandbox for Claude Code/Codex
Lock permissions before autonomy—three sandbox levels you can apply in about 15 minutes.
Editorial original
Written by WayToClawEarn editorial; cite this page as the primary analysis.
Tutorial Objectives
Add a permission sandbox to your commonly used AI programming agents (Claude Code, Codex CLI, Cursor) in 15 minutes - preventing AI from unknowingly bypassing system restrictions and performing dangerous operations.
Why do we need a sandbox?
In June 2026, a developer shared a thrilling experience on HN: Codex "creatively" found a way to bypass restrictions on a machine without sudo permissions - it discovered a legacy setuid binary, through which it indirectly performed operations that required privilege escalation (382 points, 184 comments).
This is not a problem with Codex and is a common feature of all AI programming agents: they are trained to "get the job done" and actively search for alternative paths when encountering permission obstacles. Today, when AI is given full terminal access, sandboxing is no longer optional but standard.
What you will learn
- 3 progressive sandbox solutions (from lightweight to enterprise level)
- Specific commands and configurations for each scenario
- How to ensure safety without sacrificing efficiency
Overall architecture
| Level | Solution | Security | Applicable scenarios | Implementation time |
|---|---|---|---|---|
| L1 lightweight | File system permission restrictions | ⭐⭐ | Daily use by individual developers | 5 minutes |
| L2 standard | Docker container isolation | ⭐⭐⭐⭐ | Multi-project parallelism, environment isolation | 10 minutes |
| L3 Enterprise | Firejail + Approval Flow | ⭐⭐⭐⭐⭐ | Team Collaboration, Sensitive Code Base | 15 Minutes |
Step 1: File system permission restrictions (L1, 5 minutes)
The most lightweight solution, no additional software required, suitable for daily use.
Principle
When the AI Agent is running, it can only access the specified directory and cannot read or modify files outside the project. Achieved via dedicated user + directory permissions.
Specific operations
# 1.
sudo useradd -m -s /bin/bash aiagent
# 2.
sudo mkdir -p /opt/ai-projects/my-project
sudo chown aiagent:aiagent /opt/ai-projects/my-project
# 3. Agent
sudo -u aiagent claudeClaude Code, .claude/settings.json
{
"permissions": {
"allow": ["/opt/ai-projects/**"],
"deny": ["/etc/**", "/home/**", "/root/**"],
"requireApproval": ["sudo", "rm -rf", "chmod 777"]
}
}Claude Code ,。
2 Docker (L2,10 )
Docker ——Agent ,。
Agent
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y git curl build-essential
RUN useradd -m agent && usermod -aG sudo agent
USER agent
WORKDIR /workspacedocker build -t ai-agent-sandbox .
docker run -it --rm \
--read-only \
--tmpfs /tmp:rw,noexec,nosuid,size=2G \
--tmpfs /workspace:rw,noexec,nosuid,size=5G \
-v "$(pwd):/workspace/project:ro" \
--cap-drop=ALL \
--cap-add=DAC_OVERRIDE \
--memory=4g \
--cpus=2 \
ai-agent-sandbox--read-only | |
--tmpfs /workspace | , |
--cap-drop=ALL | Linux capabilities |
--memory=4g |
3 Firejail + (L3,15 )
—— Firejail 。
Firejail
# macOS
brew install firejail
# Linux
sudo apt install firejailClaude Code
# /etc/firejail/claude-code.profile
include /etc/firejail/default.profile
net none
private-tmp
private-dev
read-only ~/.ssh
blacklist ~/.aws
blacklist ~/.config/gcloud
whitelist ~/projectsFirejail Agent
firejail --profile=claude-code.profile claude.ai-security-rules.yaml
rules:
- pattern: "rm -rf"
require_approval: true
approvers: ["tech-lead"]
- pattern: "git push.*main|master"
require_approval: true
- pattern: "curl.*\\|.*sh"
require_approval: true
message: " curl pipe bash "
- pattern: "pip install|npm install -g"
require_approval: trueQ1 Agent ?
,。( net none)、、Git 。
Q2Docker Firejail ?
Docker(), Firejail(, Git )。 AI Agent,Docker —— Agent 。
Q3M4 Mac Docker ?
Apple Silicon Docker ARM,AI Agent I/O 。( API )。
Claude Code、Codex CLI、Cursor、Docker、Firejail.
Next action
- Want to know the value of Claude Code’s security research? → Security researcher uses Claude Code for vulnerability mining: a real case of monthly income $10,000
- Still haven't decided which Agent to use? → How to choose AI programming Agent? Three-dimensional comparison of language, model and cost.
- Want to make your automated workflow more reliable? → How to add quality gates to your AI automation workflow: A practical guide from output to trustworthy results
Related tutorials
Claude Code Pricing Guide: Plans, Credits, and Cost Optimization (2026)
I spend $80-150/month on Claude Code and use it 6-7 days a week. This guide breaks down exactly how Claude Code pricing works: per-token API billing, Anthropic credits, Max mode costs, the June 2026 billing change, and real monthly budgets from three developer profiles. I also share the six cost optimization techniques that cut my bill from $340 to $80 without reducing how much I ship.
AI Coding Agents Complete Guide: Setup, Security, Workflow & Case Studies
If you are researching AI coding agents and want to know which one to use, how to set it up safely, and what real developers are building with them — this hub organizes every tutorial, case study, and comparison we have published. Start with the decision guide below to find the right path for your skill level and goals.
Claude Code Hub: Complete Knowledge Base for AI Coding with Anthropic's Agent
Claude Code is Anthropic's agentic AI coding tool that lives in your terminal. This hub organizes every tutorial, case study, comparison guide, and FAQ we have published about Claude Code — from your first install to advanced MCP server building and real-world revenue case studies. Whether you are new to AI coding or a veteran builder, this is your complete Claude Code reference.
Topic hub
AI Coding Tools Hub (2026)
From Copilot pricing changes to Claude Code + DeepSeek cost-saving setups—one place to compare tools, read explainers, and follow tutorials.
Explore AI Coding Tools Hub (2026) →Monetization angle
How can you make money from this trend?
WayToClawEarn focuses on verified earn playbooks—not just news. Start from these cases.
DeepSeek + Claude Code Micro SaaS
Run multiple small products on cheap inference
Claude Code bug bounty
Productize agent skills into security services
Related tutorials
- Claude Code Too Expensive? Cut 90%+ Cost with DeepSeek V4 in 10 Minutes
- GitHub Copilot Pricing 2026: Plan Comparison, Monthly Cost, and 3 Ways to Save
- How to turn off signature in VS Code Copilot AI: remove Co-Authored-by with one line of command
- Copilot vs Cursor vs Claude Code (2026): Which Should You Pick?
Related news
- DeepSeek Harness v0.2 Desktop Launch: Zero-Config AI Coding Agent, How to Choose?
- Google Gemini 4 Argon Released: 1M Output Tokens, DeepSWE SOTA — How It Compares for Coding and Cyber Defense
- OpenAI DevDay 2026: GPT-6.1 Sol at 1/5 Astra Price, Dots Autonomous Agent, Codex Cloud — What Developers Need to Know
- Plugin4Shell: Zero-click RCE hits four major AI coding agents — how to fix