pi-supersafety

When the example safety extensions don't cover what you need, this should! Approval flow for shell commands, file operations and every other tool (codemode, web_fetch, MCP, extension tools), plus Windows sandbox capability (with Sandboxie)

Packages

Package details

extension

Install pi-supersafety from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-supersafety
Package
pi-supersafety
Version
1.1.0
Published
Dec 1, 2026
Downloads
312/mo · 80/wk
Author
zenforic
License
MIT
Types
extension
Size
119.1 KB
Dependencies
0 dependencies · 2 peers
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi-supersafety

Comprehensive safety extension for pi that requires approval before executing commands, file operations and any other tool pi can run.

Requirements

pi-supersafety 1.1.0 imports the current pi package scope (@earendil-works/pi-coding-agent, @earendil-works/pi-tui), so it needs pi 1.x. For pi 0.x (the @mariozechner/* scope) use pi-supersafety 1.0.1.

Features

  • Shell command approval — Every bash/PowerShell command requires user approval before execution (Claude Code style), or only dangerous ones in "smart" mode
  • Chain-aware parsing — One-liners like cd out && rm -rf build; echo done are split into segments, so a dangerous command is never hidden at the tail of a chain, and "Allow all git commands" never silently approves git status && rm -rf out
  • User command approval — ! and !! user commands are gated with the same rules
  • File operation gating — Write/edit (and optionally read/grep/find/ls) operations outside the project directory require approval
  • Other tools gate — Approval for everything else pi can run: codemode, web_search, web_fetch, ask_user_question, MCP tools (mcp__server__tool) and any tool registered by another extension — including tools that do not exist yet
  • Sandboxie integration — "Run Sandboxed" option launches commands inside a Sandboxie sandbox (Windows only — see macOS/Linux note)
  • Destructive command detection — rm -rf, sudo, format, find -delete, git reset --hard, git push --force, git clean -fd, docker … prune, bash -c "…", taskkill /F, Remove-Item -Recurse, … plus your own bash.extraDestructivePatterns
  • Session-level auto-approval — "Allow All [Category] Commands", "Allow All <tool> Calls" and "Allow All Other Tools" stop the prompts for the rest of the session (/supersafety-reset clears them)
  • Deny with reason — Type a message that is sent back to the agent explaining why the call was blocked, guiding its next step
  • Timeout + keyboard shortcuts — Dialogs auto-deny after a configurable timeout; 1–9 jumps straight to an option
  • Flexible configuration — Global + per-project config, master on/off switch, headless (pi -p) behaviour
  • Bundled skill — sandboxie-boxing skill teaches the LLM about sandboxed execution

Installation

Install via pi directly:

pi install npm:pi-supersafety

Or copy this directory to your pi extensions folder:

~/.pi/agent/extensions/pi-supersafety/

Or reference it directly:

pi -e "./path/to/pi-supersafety/index.ts"

Loading a local copy while the npm package is installed registers --no-supersafety twice. Test with pi -ne -e ./index.ts, which disables extension auto-discovery but still loads the file you pass.

Configuration

Create a config file at one of these locations (project overrides global):

Global: ~/.pi/agent/extensions/supersafety.json (also ~/.pi/supersafety.json) Project: <project>/.pi/supersafety.json

This project override is a pi-supersafety feature, not pi itself: the file is read for the directory pi was started in (ctx.cwd), and it is not searched for in parent directories. The config is re-read on session start and on /supersafety; use /supersafety-enable / /supersafety-disable for session-only changes.

{
  "enabled": true,
  "approvalTimeoutSeconds": 120,
  "nonInteractive": "deny",
  "bash": {
    "enabled": true,
    "checkProjectFolder": true,
    "tools": ["bash", "powershell"],
    "extraDestructivePatterns": ["ansible-playbook"],
    "sandbox": {
      "enabled": true,
      "boxName": "DefaultBox",
      "startPath": "C:\\Program Files\\Sandboxie-Plus\\Start.exe"
    }
  },
  "fileOperations": {
    "enabled": true,
    "outsideProjectOnly": true,
    "tools": ["write", "edit", "bash"],
    "allowedPaths": []
  },
  "otherTools": {
    "enabled": true,
    "include": [],
    "exclude": ["read", "grep", "find", "ls", "ask_user_question"],
    "sessionApprovals": true,
    "allowAllToolsApproval": true,
    "maxArgPreview": 400
  }
}

Configuration Options

Option Default Description
enabled true Master on/off switch for all safety features
approvalTimeoutSeconds 120 Auto-deny a pending dialog after N seconds (0 = wait forever)
nonInteractive "deny" What happens when there is no dialog-capable UI (pi -p, JSON mode, SDK): "deny" blocks everything that would prompt, "allow" skips the prompts
bash.enabled true Enable shell command approval
bash.checkProjectFolder true When true, ALL commands need approval. When false, only destructive commands are checked
bash.tools ["bash", "powershell"] Tool names treated as shell commands (approval + sandbox wrapping)
bash.extraDestructivePatterns [] Extra case-insensitive regex sources that mark a command destructive
bash.sandbox.enabled true Offer "Run Sandboxed" option in approval dialog
bash.sandbox.boxName "DefaultBox" Name of the Sandboxie box to use
bash.sandbox.startPath auto-detected Path to Sandboxie Start.exe
fileOperations.enabled true Enable file operation approval
fileOperations.outsideProjectOnly true When true, only file ops outside project need approval. When false, ALL file ops need approval
fileOperations.tools ["write", "edit", "bash"] Which tools to gate. Add "read", "grep", "find", "ls" (or any custom tool with a path argument) to gate reads too
fileOperations.allowedPaths [] Paths that always bypass approval
otherTools.enabled true Gate every tool that has no dedicated rule (codemode, web_fetch, MCP, extension tools)
otherTools.include [] Tool-name patterns to gate; empty = everything not handled elsewhere. * wildcards supported, e.g. ["mcp__*", "web_*"]
otherTools.exclude ["read", "grep", "find", "ls", "ask_user_question"] Tool-name patterns never gated (wins over include)
otherTools.sessionApprovals true Offer "Allow All <tool> Calls"
otherTools.allowAllToolsApproval true Offer "Allow All Other Tools" (one approval unlocks the rest)
otherTools.maxArgPreview 400 Characters of tool arguments shown in the dialog (0 hides them)

Gating "the other stuff"

otherTools is the tool-name-agnostic gate. By default it approves or denies:

  • codemode, tool_search
  • web_search, web_fetch, ask_user_question (the question tool is excluded by default because it already asks you something)
  • MCP tools such as mcp__rea__decompile (shown with the server name in the dialog)
  • Any tool registered by another extension, present or future

Examples:

// Only gate MCP tools and codemode
"otherTools": { "enabled": true, "include": ["mcp__*", "codemode"] }

// Gate everything, reads included
"otherTools": { "enabled": true, "exclude": [] }

// Silence the generic gate but keep shell/file gating
"otherTools": { "enabled": false }

Approval Dialogs

All dialogs support ↑/↓ navigation, 1–9 shortcuts, Enter to select and Esc to cancel, and auto-deny after approvalTimeoutSeconds.

Shell Commands

When a bash/PowerShell command needs approval you will see up to five options (some are conditional):

Option When shown Description
Allow Always Run the command normally
Deny Always Block the command
Allow All [Category] Commands When every segment of the line belongs to a known tool (e.g. git, npm, docker) Approve all commands of that category for the rest of the session — no more prompts for git status, git push, etc.
Run Sandboxed (BoxName) When bash.sandbox.enabled is true and Start.exe is found Run the command inside a Sandboxie sandbox
Type reason… Always Opens an inline text editor — your message is sent to the agent as the denial reason, guiding its next step

Chained one-liners are listed one segment per line, with a ⚠ note naming the flagged segment (for example rm (rm) or taskkill (kill)).

File Operations

When a file operation needs approval you will see three options:

Option Description
Allow Proceed with the file operation
Deny Block the operation
Type reason… Deny and send a typed message back to the agent

Other Tools

When any other tool needs approval you will see up to five options:

Option When shown Description
Allow Always Run this single call
Deny Always Block this call
Allow All "" Calls When otherTools.sessionApprovals is true Auto-approve that tool for the rest of the session
Allow All Other Tools When otherTools.allowAllToolsApproval is true Auto-approve every remaining generic tool for the rest of the session
Type reason… Always Deny and send a typed message back to the agent

The dialog shows the tool name, where it comes from (built-in / extension / MCP + server name) and a truncated preview of its arguments.

Chain-Aware Command Parsing

Before deciding, a command string is split into segments on unquoted ;, newline, &&, ||, |, |& and background &. Quoted text ("…"/'…'), $(…)/(...) groups and redirections (2>&1, &>log) are kept intact, so git commit -m "fix: a && b" stays one command.

Each segment is then resolved to the program it actually runs, skipping sudo, env, nohup, time, xargs and leading FOO=bar assignments. That result drives:

  • Destructive detection — one dangerous segment makes the whole line require approval
  • Category auto-approval — an "Allow all git commands" choice only skips future prompts when all segments of a line are git (and nothing is destructive)
  • Sandbox wrapping — lines that need a shell get the cmd.exe /c (or powershell.exe -Command) wrapper; simple commands run directly

Commands

Command Description
/supersafety Show current configuration, status and session auto-approvals
/supersafety-enable Enable supersafety for this session
/supersafety-disable Disable supersafety for this session
/supersafety-reset Clear session auto-approvals (categories and tools)

CLI Flags

Flag Description
--no-supersafety Disable supersafety entirely

Disabling

To disable the extension:

  1. Per session: Use /supersafety-disable
  2. Per project: Set "enabled": false in .pi/supersafety.json
  3. Globally: Set "enabled": false in ~/.pi/agent/extensions/supersafety.json
  4. Via CLI: Run pi --no-supersafety

Sandboxie Setup (Windows)

For the sandbox feature to work:

  1. Install Sandboxie-Plus
  2. Ensure Start.exe is in one of the standard locations (auto-detected)
  3. Or specify the path in config: "startPath": "C:\\Program Files\\Sandboxie-Plus\\Start.exe"

Note: Sandboxie is a Windows-only tool. See the section below if you are on macOS or Linux.

macOS / Linux Users

The Sandboxie sandbox integration is Windows-only. On macOS or Linux you should disable it to avoid unnecessary warnings:

{
  "bash": {
    "sandbox": {
      "enabled": false
    }
  }
}

All other features (command approval, other-tool gating, file operation gating, deny-with-reason, session allow-all) work normally on every platform.

For sandboxed execution on macOS or Linux you can use a compatible pi sandbox extension instead. The official pi repository includes an example sandbox extension that you can use as a starting point, or search for a community extension that wraps a platform-native sandbox (e.g. firejail, bubblewrap, or macOS Sandbox).

Bundled Skill

The sandboxie-boxing skill is automatically registered and available via /skill:sandboxie-boxing. It provides the LLM with comprehensive documentation about Sandboxie Start.exe commands and usage patterns.

Development

npm install          # dev tooling (typescript, jiti, @types/node)
npm run typecheck    # tsc --noEmit against the pi 1.x types
npm test             # command/config tests + jiti smoke test of the real handlers
npm run check        # both

Try it in pi without installing:

pi -ne -e ./index.ts

Files

File Purpose
index.ts Extension entry: event handlers, commands, status bar, sandbox wrapping
command.ts Chain-aware segmentation, destructive rules, command categories
approval.ts Approval dialogs (shell, file, generic tool)
config.ts Config types, defaults, global + project merge, tool-pattern matching
preview.ts Tool-agnostic argument previews and path extraction
sandbox.ts Standalone Sandboxie Start.exe wrapper and executor
test/ command.test.ts, tools.test.ts, smoke.test.mjs