Sandboxed Bash replaces the standard root-session bash tool with a sandboxed execution layer. Every shell command passes through a policy engine and a platform-specific isolation adapter before reaching the host. If no sandbox tool is available on the current platform, the system falls back to unsandboxed execution with explicit user approval.
μλλ°μ€ Bashλ νμ€ root-session bash λꡬλ₯Ό μλλ°μ€ μ€ν λ μ΄μ΄λ‘ κ΅μ²΄ν©λλ€. λͺ¨λ μ
Έ λͺ
λ Ήμ νΈμ€νΈμ λλ¬νκΈ° μ μ μ μ±
μμ§κ³Ό νλ«νΌλ³ 격리 μ΄λν°λ₯Ό κ±°μΉ©λλ€. νμ¬ νλ«νΌμ μλλ°μ€ λκ΅¬κ° μμΌλ©΄, λͺ
μμ μΈ μ¬μ©μ μΉμΈκ³Ό ν¨κ» μλλ°μ€ μλ μ€νμΌλ‘ ν΄λ°±ν©λλ€.
Root sessions register a tool labeled "bash (sandboxed)". When the agent issues a bash command, the execution pipeline is:
Root μΈμ μ "bash (sandboxed)"λΌλ λ μ΄λΈμ λꡬλ₯Ό λ±λ‘ν©λλ€. μμ΄μ νΈκ° bash λͺ λ Ήμ λ°ννλ©΄ μ€ν νμ΄νλΌμΈμ λ€μκ³Ό κ°μ΅λλ€:
Command β Policy Engine β Platform Adapter (bwrap | sandbox-exec) β Executionλͺ λ Ή β μ μ± μμ§ β νλ«νΌ μ΄λν° (bwrap | sandbox-exec) β μ€ν
Bash is launched as:
Bashλ λ€μκ³Ό κ°μ΄ μ€νλ©λλ€:
bash -lc <command>
The policy engine evaluates platform capability, filesystem mode, and network mode to produce a sandbox decision. If the decision is sandboxed, the platform adapter wraps the command in the appropriate isolation mechanism. If the decision is unsandboxed, the approval flow determines whether execution is permitted.
μ μ±
μμ§μ νλ«νΌ κΈ°λ₯, νμΌμμ€ν
λͺ¨λ, λ€νΈμν¬ λͺ¨λλ₯Ό νκ°νμ¬ μλλ°μ€ κ²°μ μ λ΄λ¦½λλ€. κ²°μ μ΄ sandboxedμ΄λ©΄ νλ«νΌ μ΄λν°κ° λͺ
λ Ήμ μ μ ν 격리 λ©μ»€λμ¦μΌλ‘ κ°μλλ€. κ²°μ μ΄ unsandboxedμ΄λ©΄ μΉμΈ νλ¦μ΄ μ€ν νμ© μ¬λΆλ₯Ό κ²°μ ν©λλ€.
Each platform has a dedicated adapter that provides sandbox capability detection and launch construction:
κ° νλ«νΌμλ μλλ°μ€ κΈ°λ₯ κ°μ§ λ° μ€ν ꡬμ±μ μ 곡νλ μ μ© μ΄λν°κ° μμ΅λλ€:
| Platformνλ«νΌ | Commandλͺ λ Ή | Mechanismλ©μ»€λμ¦ |
|---|---|---|
| Linux | bwrap |
bubblewrap namespace isolationbubblewrap λ€μμ€νμ΄μ€ 격리 |
| macOS | sandbox-exec |
Apple sandbox profileApple μλλ°μ€ νλ‘ν |
The Linux adapter uses bubblewrap for namespace-level isolation. The full launch command:
Linux μ΄λν°λ λ€μμ€νμ΄μ€ μμ€ κ²©λ¦¬λ₯Ό μν΄ bubblewrapμ μ¬μ©ν©λλ€. μ 체 μ€ν λͺ λ Ή:
bwrap \ --die-with-parent \ --new-session \ --ro-bind / / \ --proc /proc \ --dev /dev \ --tmpfs /tmp \ --bind <workspace> <workspace> \ --chdir <cwd> \ [--unshare-net] \ -- <command>
Flags explained:
νλκ·Έ μ€λͺ :
--die-with-parent β
Kill the sandbox if the parent process dies.
λΆλͺ¨ νλ‘μΈμ€κ° μ’
λ£λλ©΄ μλλ°μ€λ₯Ό μ’
λ£ν©λλ€.
--new-session β
Create a new process session.
μ νλ‘μΈμ€ μΈμ
μ μμ±ν©λλ€.
--ro-bind / / β
Mount the root filesystem read-only.
λ£¨νΈ νμΌμμ€ν
μ μ½κΈ° μ μ©μΌλ‘ λ§μ΄νΈν©λλ€.
--proc /proc β
Mount a new proc filesystem.
μ proc νμΌμμ€ν
μ λ§μ΄νΈν©λλ€.
--dev /dev β
Mount a minimal /dev.
μ΅μνμ /devλ₯Ό λ§μ΄νΈν©λλ€.
--tmpfs /tmp β
Mount a fresh tmpfs at /tmp.
/tmpμ μ tmpfsλ₯Ό λ§μ΄νΈν©λλ€.
--bind <workspace> <workspace> β
Bind-mount the workspace read-write.
μν¬μ€νμ΄μ€λ₯Ό μ½κΈ°-μ°κΈ°λ‘ λ°μΈλ λ§μ΄νΈν©λλ€.
--chdir <cwd> β
Set working directory inside the sandbox.
μλλ°μ€ λ΄ μμ
λλ ν 리λ₯Ό μ€μ ν©λλ€.
--unshare-net β
Disable network access (when network mode is "off").
λ€νΈμν¬ μ‘μΈμ€ λΉνμ±ν (λ€νΈμν¬ λͺ¨λκ° "off"μΌ λ).
The adapter runs which bwrap to detect availability. If bwrap is not installed, the system falls back to unsandboxed execution with approval.
μ΄λν°λ which bwrapλ₯Ό μ€ννμ¬ μ¬μ© κ°λ₯ μ¬λΆλ₯Ό κ°μ§ν©λλ€. bwrapμ΄ μ€μΉλμ΄ μμ§ μμΌλ©΄ μΉμΈκ³Ό ν¨κ» μλλ°μ€ μλ μ€νμΌλ‘ ν΄λ°±ν©λλ€.
The macOS adapter uses Apple's sandbox-exec with a dynamically generated SBPL profile. The profile is written to a temporary file and cleaned up after execution:
macOS μ΄λν°λ λμ μΌλ‘ μμ±λ SBPL νλ‘νκ³Ό ν¨κ» Appleμ sandbox-execλ₯Ό μ¬μ©ν©λλ€. νλ‘νμ μμ νμΌμ κΈ°λ‘λκ³ μ€ν ν μ 리λ©λλ€:
(version 1)
(deny default)
(import "system.sb")
(allow process*)
(allow sysctl-read)
(allow file-read*)
(allow file-write*
(subpath "<workspace>")
(subpath "/tmp")
(subpath "<tmpdir>"))
(allow network*) # when network mode is "on"
Profile explained:
νλ‘ν μ€λͺ :
(deny default) β
Deny all operations by default.
κΈ°λ³Έμ μΌλ‘ λͺ¨λ μμ
μ κ±°λΆν©λλ€.
(import "system.sb") β
Import macOS system sandbox defaults.
macOS μμ€ν
μλλ°μ€ κΈ°λ³Έκ°μ μν¬νΈν©λλ€.
(allow process*) β
Allow process creation and signal operations.
νλ‘μΈμ€ μμ± λ° μκ·Έλ μμ
μ νμ©ν©λλ€.
(allow sysctl-read) β
Allow reading system information.
μμ€ν
μ 보 μ½κΈ°λ₯Ό νμ©ν©λλ€.
(allow file-read*) β
Allow reading any file.
λͺ¨λ νμΌ μ½κΈ°λ₯Ό νμ©ν©λλ€.
(allow file-write* ...) β
Restrict writes to workspace, /tmp, and the system tmpdir.
μ°κΈ°λ₯Ό μν¬μ€νμ΄μ€, /tmp, μμ€ν
tmpdirλ‘ μ νν©λλ€.
(allow network*) β
Enable network access (only when network mode is "on").
λ€νΈμν¬ μ‘μΈμ€ νμ±ν (λ€νΈμν¬ λͺ¨λκ° "on"μΌ λλ§).
The adapter runs which sandbox-exec to detect availability. If sandbox-exec is not available, the system falls back to unsandboxed execution with approval.
μ΄λν°λ which sandbox-execλ₯Ό μ€ννμ¬ μ¬μ© κ°λ₯ μ¬λΆλ₯Ό κ°μ§ν©λλ€. sandbox-execμ μ¬μ©ν μ μμΌλ©΄ μΉμΈκ³Ό ν¨κ» μλλ°μ€ μλ μ€νμΌλ‘ ν΄λ°±ν©λλ€.
When sandbox capability is unavailable or the policy engine decides unsandboxed execution is needed, the approval flow gates command execution. The mode is controlled via the PI_SANDBOX_APPROVAL_MODE environment variable:
μλλ°μ€ κΈ°λ₯μ μ¬μ©ν μ μκ±°λ μ μ±
μμ§μ΄ μλλ°μ€ μλ μ€νμ΄ νμνλ€κ³ κ²°μ ν λ, μΉμΈ νλ¦μ΄ λͺ
λ Ή μ€νμ μ μ΄ν©λλ€. λͺ¨λλ PI_SANDBOX_APPROVAL_MODE νκ²½ λ³μλ‘ μ μ΄λ©λλ€:
| Modeλͺ¨λ | Behaviorλμ |
|---|---|
ask |
Prompt the user for each unsandboxed command (default). μλλ°μ€ μλ κ° λͺ λ Ήμ λν΄ μ¬μ©μμκ² ν둬ννΈ (κΈ°λ³Έκ°). |
always |
Auto-approve all unsandboxed fallbacks. λͺ¨λ μλλ°μ€ μλ ν΄λ°±μ μλ μΉμΈ. |
deny |
Block all unsandboxed execution. λͺ¨λ μλλ°μ€ μλ μ€νμ μ°¨λ¨. |
Approval choices presented to the user:
μ¬μ©μμκ² μ μλλ μΉμΈ μ ν:
Approval scopes:
μΉμΈ λ²μ:
once β
Single execution, no persistence.
λ¨μΌ μ€ν, μμμ± μμ.
session β
Cached for the session with a configurable TTL (default 6 hours, PI_SANDBOX_SESSION_APPROVAL_TTL_MS).
κ΅¬μ± κ°λ₯ν TTLλ‘ μΈμ
λμ μΊμλ¨ (κΈ°λ³Έ 6μκ°, PI_SANDBOX_SESSION_APPROVAL_TTL_MS).
always β
Persisted to disk and never expires.
λμ€ν¬μ μꡬ μ μ₯λλ©° λ§λ£λμ§ μμ.
Approvals are persisted to ~/.pi/agent/sandbox-approvals.json using a versioned format (v2) that supports both scope types and expiration timestamps.
μΉμΈμ λ λ²μ μ νκ³Ό λ§λ£ νμμ€ν¬νλ₯Ό λͺ¨λ μ§μνλ λ²μ κ΄λ¦¬ νμ(v2)μ μ¬μ©νμ¬ ~/.pi/agent/sandbox-approvals.jsonμ μꡬ μ μ₯λ©λλ€.
The sandbox system detects files that may contain sensitive environment variables. A file is flagged as sensitive if its basename matches .env or starts with .env. (e.g., .env.local, .env.production).
μλλ°μ€ μμ€ν
μ λ―Όκ°ν νκ²½ λ³μλ₯Ό ν¬ν¨ν μ μλ νμΌμ κ°μ§ν©λλ€. νμΌμ λ² μ΄μ€λ€μμ΄ .envμ μΌμΉνκ±°λ .env.λ‘ μμνλ©΄(μ: .env.local, .env.production) λ―Όκ°ν κ²μΌλ‘ νμλ©λλ€.
When PI_SANDBOX_APPROVAL_MODE=deny, reads of sensitive .env* files are blocked entirely.
PI_SANDBOX_APPROVAL_MODE=denyμΌ λ, λ―Όκ°ν .env* νμΌ μ½κΈ°κ° μμ ν μ°¨λ¨λ©λλ€.
| Env Varνκ²½ λ³μ | Valuesκ° | DefaultκΈ°λ³Έκ° | Descriptionμ€λͺ |
|---|---|---|---|
PI_SANDBOX_APPROVAL_MODE |
ask, always, deny |
ask |
Approval behavior for unsandboxed fallback execution. μλλ°μ€ μλ ν΄λ°± μ€νμ λν μΉμΈ λμ. |
If neither bwrap nor sandbox-exec is present (or the platform is unsupported), the system falls back to unsandboxed execution. The approval prompt is presented to the user unless PI_SANDBOX_APPROVAL_MODE=always or =deny overrides it.
bwrapμ΄λ sandbox-execμ΄ μκ±°λ νλ«νΌμ΄ μ§μλμ§ μλ κ²½μ°, μμ€ν
μ μλλ°μ€ μλ μ€νμΌλ‘ ν΄λ°±ν©λλ€. PI_SANDBOX_APPROVAL_MODE=always λλ =denyκ° μ¬μ μνμ§ μλ ν μ¬μ©μμκ² μΉμΈ ν둬ννΈκ° νμλ©λλ€.
In addition to the workspace root, the sandbox allows writes to the Pi agent directory and session directory. These are resolved from PI_CODING_AGENT_DIR and PI_CODING_AGENT_SESSION_DIR (defaulting to ~/.pi/agent and the session temp dir respectively).
μν¬μ€νμ΄μ€ λ£¨νΈ μΈμλ μλλ°μ€λ Pi μμ΄μ νΈ λλ ν 리μ μΈμ
λλ ν 리μ μ°κΈ°λ₯Ό νμ©ν©λλ€. μ΄λ€μ PI_CODING_AGENT_DIRκ³Ό PI_CODING_AGENT_SESSION_DIRμμ ν΄κ²°λ©λλ€ (κΈ°λ³Έκ°μ κ°κ° ~/.pi/agentμ μΈμ
μμ λλ ν 리).
Network access is configurable per execution. When set to "off", Linux uses --unshare-net and macOS omits the (allow network*) clause from the SBPL profile. When set to "on", full network access is permitted within the sandbox.
λ€νΈμν¬ μ‘μΈμ€λ μ€νλ§λ€ ꡬμ±ν μ μμ΅λλ€. "off"λ‘ μ€μ νλ©΄ Linuxλ --unshare-netμ μ¬μ©νκ³ macOSλ SBPL νλ‘νμμ (allow network*) μ μ μλ΅ν©λλ€. "on"μΌλ‘ μ€μ νλ©΄ μλλ°μ€ λ΄μμ μ 체 λ€νΈμν¬ μ‘μΈμ€κ° νμ©λ©λλ€.