← Catalog

@kaelvio/pi-security

A Linux sandbox for Pi tools with file and network grants, automatic review, and manual approval.

Package

Install

Install with PiG

pig install npm:@kaelvio/pi-security

Install with Pi

pi install npm:@kaelvio/pi-security
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./src/extension.js"
  ]
}

README

Written by the package's publisher, shown as published in version 0.4.0 (README.md). PiG does not review it.

@kaelvio/pi-security

A Linux sandbox and permission manager for Pi, inspired by Linden.

Pi runs the agent's bash, read, write, edit, ls, grep, and find tools inside Bubblewrap (bwrap). Ordinary workspace operations run without a prompt. A tool can request access to a specific path or ask to run one call with your OS user's permissions. Commands you enter with ! or !! use Pi's built-in shell behavior. Third-party tools and MCP servers run outside this extension's sandbox.

Installation

Use Linux with unprivileged user namespaces and Node.js 22.19.0 or newer. The extension has been tested with Pi 1.6.1, Node.js 22.21.1, and Bubblewrap 0.9.0.

The sandbox needs Bash, /usr/bin/bwrap, /usr/bin/python3, libseccomp.so.2, /usr/bin/flock, and /usr/bin/socat. The grep and find tools also use rg and fd from the system or the Pi agent's bin directory.

Install the npm package with Pi.

pi install npm:@kaelvio/pi-security

To try a local checkout, run these commands from the repository root.

npm install
pi --no-extensions -e "$PWD/src/extension.js"

To keep using the checkout across sessions, run pi install "$PWD" from the same directory.

Install the extension and its toolchain in a trusted location. The sandbox gives the installation directory read-only protection by default. Sandboxed processes receive a dedicated PATH and a minimal environment. Automatic review uses your existing Pi login.

Configuration

Configure the extension under pi-sandbox-permissions in your user-level Pi agent settings.json. The defaults are a writable workspace, an outbound network allowlist, and automatic permission review. This example limits outbound access to the npm registry and disables requests to run outside the sandbox.

{
  "pi-sandbox-permissions": {
    "sandbox": {
      "defaultMode": "workspace-write",
      "allowUnsandboxedCommands": false,
      "filesystem": { "readBase": "root", "writableTemp": true, "additionalReadPaths": [], "additionalWritePaths": [] },
      "network": {
        "mode": "allowlist",
        "allow": [{ "host": "registry.npmjs.org", "port": 443 }],
        "deny": []
      }
    },
    "permission": {
      "defaultMode": "auto",
      "allow": [],
      "deny": []
    }
  }
}

Sandbox

The default read base is the host filesystem, subject to your OS user's access and explicit deny rules. The directory where you start Pi is the workspace. In workspace-write, the workspace, /tmp, and the OS temporary directory are writable. Starting in your home directory lets tools create, rename, and save ordinary files there. Starting in another project still lets tools read home files, including Pi session files.

Set sandbox.filesystem.readBase to minimal to expose the workspace, system tools, and Pi runtime plus your configured paths. Set writableTemp to false to remove the default writable host temporary roots. A temporary directory you explicitly select as your workspace still takes the workspace mode. additionalReadPaths and additionalWritePaths accept existing canonical absolute paths. The read-only file mode caps workspace, configured, and saved write access at read access. An approved single-call write request can write its target in either mode.

Workspace metadata (.git, .agents, .codex, and .aws), linked Git metadata, Pi settings, the grant store, and the extension and Pi installations have read-only defaults inside a writable root. A write grant naming the protected path or a file inside it can override that default. User deny rules take precedence.

Set sandbox.network.mode to off or allowlist. Both modes use an isolated network namespace and a host proxy. Clients that honor HTTP proxy environment variables can use HTTP or HTTPS CONNECT. The proxy resolves hosts to IPv4 addresses on the host and enforces exact host and port matches. Direct outbound connections, direct DNS from inside the sandbox, and raw UDP are blocked.

The default allowlist permits port 443 on the following hosts.

PurposeHosts
Development dependenciesregistry.npmjs.org, pypi.org, files.pythonhosted.org, crates.io, index.crates.io, static.crates.io
Academic papers and metadataarxiv.org, export.arxiv.org, api.crossref.org, api.openalex.org

Setting sandbox.network.allow replaces the entire default list. An empty array starts with no destinations. You can add individual endpoints with resource grants.

Permissions and review

permission.defaultMode accepts auto or manual. Use permission.allow and permission.deny to manage requests for additional access. Allow rules match the full requested permission. A filesystem deny applies to its path and descendants on every sandboxed call. An approved parent directory retains its other permissions. An fs.write deny makes the child read-only, and an fs.read deny blocks reading and writing the child.

Requested permissionExample
Read a file or directory{"kind":"fs.read","path":"/srv/docs"}
Read and write a file or directory{"kind":"fs.write","path":"/srv/output"}
Run one call with the OS user's permissions{"kind":"unsandboxed"}

Tools request scoped access with an additional_permissions array and a justification. To run outside the sandbox, a tool must request sandbox_permissions: "require_escalated", give a reason, and obtain a separate approval. allowUnsandboxedCommands enables these requests by default. An explicit denial also blocks an unsandboxed request that would include the denied access. Once approved, an unsandboxed call can access the filesystem and network as your OS user.

The sandbox proxy denies unlisted destinations. A legacy net.connect entry in permission.allow does not add a destination to the allowlist. To allow a host, use sandbox.network.allow or add a net: resource grant.

In auto mode Pi sends the requested action to openai-codex/codex-auto-review using the default Codex Guardian policy from @mzwing/pi-permission-auto-review@1.0.2. Long conversations retain the first and most recent user evidence and prioritize other user instructions over tool output. Completed, matched answers from ask_user_question and plan_mode_question carry user provenance. The extension distinguishes those answers from text printed by tools. It excludes private user Bash output from the review.

A denial blocks the call. The reference preset pauses automatic decisions for the rest of a Pi turn after three consecutive denials or ten denials in the last fifty reviews. If the model is unavailable, returns an invalid verdict after retries, or exceeds the review budget, Pi asks for manual approval. A call needing manual approval requires an interactive UI. The bundled policy and its source revision are documented in the architecture notes.

Session controls

The status bar shows the base file mode, network mode, and approval mode, for example file read · net off · permission manual. With elevation disabled it shows file read · net off · elevation off. In file read mode, a saved sandbox write grant makes the file readable. A tool can still request fs.write explicitly. If approved, that call can write the requested path and subsequent ordinary calls have read access again. Press Alt+S to switch to a read-only workspace with manual approval. If that combination is already active, the shortcut switches to a writable workspace with automatic review.

Open /sandbox to toggle file, network, and elevation settings or open Sandbox grants to manage extra file and network access. In /permissions, toggle the approval mode or open Grants for configured approval rules and remembered tool calls. Use the arrow keys to select a row, Enter to toggle or open it, and Esc to go back.

CommandAction
/sandbox read-only, /sandbox workspace-writeSwitch the base filesystem mode.
/sandbox off, /sandbox allowlistDisable outbound network access or restore the allowlist. Turning it off disconnects active proxy connections. Running processes can open new connections once the allowlist is restored.
/sandbox elevation-off, /sandbox elevation-onHide or restore elevation parameters on agent tools. Turning elevation off rejects stale requests and cancels active elevated calls. If host execution is disabled in settings, turning elevation on permits only scoped requests.
/sandbox grantsManage session and workspace file and network grants. Select Add resource grant to add one, press Enter to edit, or Backspace or Delete to remove.
/permissions auto, /permissions manualChoose automatic review or user approval for additional permissions.
/permissions rulesList approval rules by source. Press Enter to edit or Backspace or Delete to remove.
/permissions auditShow the last 100 decisions, including matches from session grants, workspace grants, and configuration.

Mode switches apply to the current session. Editing a configured permission updates the user's settings.json. The extension stores workspace grants under sandbox-permissions in the Pi agent directory, scoped to the working directory. The audit records one-time approvals and automatic decisions. A remembered Bash approval matches the command and requested permissions. Only a limited set of git status display flags share a match. File-tool approvals also match other tool arguments, which are stored as a digest.

Sharing a grant across tools

When a tool requests access to an existing regular file, manual approval offers Expand session sandbox and Expand workspace sandbox. For example, choosing Expand session sandbox · &file:/data/paper.pdf during a read request lets subsequent sandboxed tools, including bash, read that file directly. They can omit additional_permissions. Choosing Expand on a write request approves the pending call and saves a sandbox grant. In file read mode, future write requests still go through the approval rules or reviewer. Choose workspace scope to make the grant available to other sessions in the same working directory. Allow for session and Always allow in this project remember the specific tool call.

Session grants are saved as soon as you approve, edit, or delete them. From the original working directory, run pi -c to continue the latest conversation or pi -r to select one. Resuming restores its [session] command, file, and network grants. New and forked conversations have their own grants. With --no-session, grants live only in memory.

In /sandbox grants, select a grant to edit it or choose a scope when adding one. The editor accepts one resource grant per entry.

GrantAccess
&file:/data/paper.pdfRead this file.
file:/data/results.csvRead this file in file read mode. Read and write it in file write mode.
net:api.example.org or net:api.example.org:8443Add an exact host and port to the sandbox network allowlist. The default port is 443.

File grants use canonical absolute paths. If you delete the file or replace it with a directory or symlink, the sandbox skips that mount. /sandbox controls base workspace access. Switching to elevation-off closes new elevation requests while existing resource grants continue to apply. Network grants honor net off and explicit deny rules.

A file request retains its scope while approval is pending. A remembered tool-call approval for a file applies only while the target is a file. Directory approvals saved by older versions require approval once after upgrading. An additional file permission inside a directory that already provides that access preserves ordinary saves and atomic replacement.

Editing or deleting a resource grant stops managed tool calls running in the current session. Other open sessions in the same workspace read updated workspace grants on their next tool call.

Upgrading older configurations

Upgrading changes the default filesystem view to readBase: "root" with writable host temporary directories in workspace-write mode. To limit host reads and remove those writable roots, set readBase: "minimal" and writableTemp: false. Remembered tool-call approvals include the sandbox configuration and may require approval again.

The legacy proxy mode maps to allowlist. Unlisted destinations are denied, including when an older configuration sets unknown: "ask". Older workspace grants contain only a label and a hash. Open the grants list to redefine or delete them.

Testing

npm test
REQUIRE_PROXY=1 npm test
LIVE_CODEX_REVIEW=1 npm test

The suite runs real Bubblewrap processes. The strict proxy test requires Linux to allow local TCP listeners, Unix socket listeners, and network namespaces. The opt-in live review test uses a temporary copy of your Pi login credentials. Implementation details and test coverage are documented in the architecture notes (Chinese).