AI Programming Agent Security Configuration Tutorial: 3 Steps to Add Permission Sandbox to Claude Code/Codex
Configure a three-level permission sandbox for Claude Code, Codex CLI, and Cursor within 15 minutes
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
How to Write .cursorrules: Cursor Prompt Engineering Guide (2026)
If Cursor's AI keeps generating code you have to fix every time, the problem is not the model: it is your rules file. A good .cursorrules can cut your edit-to-accept ratio from 3:1 to near 1:1. After eight months of iterating on Cursor rules across React, Python, and Go projects, this guide walks through what works, what breaks, and the templates I actually use.
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.
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