- TypeScript 50.2%
- Python 47.2%
- Shell 2.6%
| tests | ||
| .gitignore | ||
| approval.ts | ||
| client.ts | ||
| hostrun.py | ||
| index.ts | ||
| install.sh | ||
| package.json | ||
| pid-hostrun.service | ||
| README.md | ||
| tsconfig.json | ||
| uninstall.sh | ||
hostrun
A standalone, user-approved bridge from sandboxed pid / Pi to your Linux host. No VS Code component, network listener, Docker socket access, Python packages or runtime npm dependencies.
index.tsregistershost_run;client.tsconnects usingPID_HOSTRUN_SOCKET.hostrun.pyis a single-file Python 3 daemon running unsandboxed as you.- Approval happens inside Pi: a popup in the Pi TUI, or a questionnaire-style card in the pid VS Code sidebar (RPC mode). No desktop, Tk, kdialog or zenity is needed, so it works on headless hosts. Bash runs only after the extension reports approval or an exact in-memory session match.
- Trust change: the daemon trusts the approval decision sent by the sandboxed extension. Anything in the sandbox that can reach the socket could forge approval. This is a convenience and review boundary, not a security boundary against a compromised sandbox.
- The companion pid launcher change mounts
$XDG_RUNTIME_DIR/pid-hostrunread-only at/pid-hostrunfor interactive and RPC Pi launches, only if the directory exists. It exportsPID_HOSTRUN_SOCKET=/pid-hostrun/hostrun.sock. This top-level destination avoids an ambiguous nested mount under/runin the RPC policy validator, and is reserved against workspace overlap. Preparation, Claude and shell launches are unchanged. Restart existing containers/connections to pick up the mount.
Host installation
pid --install and pid --update do all of this automatically: they clone this repository under the pid install root, run install.sh and register the Pi package. Set PID_HOSTRUN=0 to opt out. The manual steps below are only needed without pid's installer. install.sh is non-interactive and idempotent; it restarts the daemon only when its files changed or a previous restart failed.
Run these steps on the host, not inside pid. Review the source first. Requirements: Linux, Python 3 and /bin/bash. No graphical desktop is required.
cd /path/to/hostrun
./install.sh
systemctl --user status pid-hostrun.service
journalctl --user -u pid-hostrun.service
The installer copies the daemon to ~/.local/lib/pid-hostrun/hostrun.py, installs ~/.config/systemd/user/pid-hostrun.service and enables/restarts the service. The unit follows default.target, so it does not depend on a graphical session.
Without systemd, run this from a host terminal:
python3 /path/to/hostrun/hostrun.py
Default socket: $XDG_RUNTIME_DIR/pid-hostrun/hostrun.sock (or /run/user/<uid>/pid-hostrun/hostrun.sock when XDG_RUNTIME_DIR is unset). The directory must be yours, non-symlink and 0700, socket 0600. Existing unsafe permissions cause startup failure, not silent chmod. A lock prevents duplicate daemons; stale sockets are recovered. Do not delete/recreate the directory while containers are running. The default launcher integration requires XDG_RUNTIME_DIR. --socket /absolute/directory/socket supports direct clients, but needs your own launcher mount and environment configuration.
Upgrade by rerunning ./install.sh. Uninstall on the host:
./uninstall.sh
The audit log is retained. Remove the copied Pi extension separately. The empty runtime directory may remain until logout; a remaining directory mounts harmlessly, and calls report that the daemon is not running.
Install the Pi extension
Pi provides TypeBox and the extension API. No runtime npm install is needed. Use a durable checkout on the host, and open a pid shell with this checkout as the workspace:
cd /path/to/hostrun
pid --shell
# Now inside the sandbox, at the mounted checkout:
mkdir -p /pi-home/agent/extensions/hostrun
cp index.ts client.ts package.json /pi-home/agent/extensions/hostrun/
exit
Start a fresh pid or reconnect RPC after the daemon is running. The copied extension is globally discovered in /pi-home/agent/extensions/hostrun/. /reload loads extension updates, but cannot add a missing container mount. Copy the files again to upgrade; remove that extension directory to uninstall. Do not point persistent settings at /tmp/hostrun, or at another workspace's unmounted local path.
For non-pid Pi installations, use pi install /absolute/durable/path/to/hostrun where that path is visible to Pi. pi -e /absolute/path/to/hostrun/index.ts is a one-invocation trial. The package manifest also supports installing from a published Git source later.
Use
Ask Pi to inspect host-only state, for example the status of a host user service. The tool takes:
{
"command": "systemctl --user status example.service --no-pager",
"description": "Check the host user service because the sandbox cannot access the host service manager.",
"impact": "read-only",
"timeout_seconds": 30
}
Optional cwd is an absolute host directory. The extension supplies the current workspace by default. The daemon uses that directory if it exists, otherwise host $HOME, and shows the effective directory before approval. Commands run as /bin/bash -lc <exact command> with stdin /dev/null, the daemon's environment, and an independent process group. No sandbox-provided environment object is accepted. Login-shell startup files can alter the environment and cwd. Interactive commands and sudo password prompts are not supported.
Approval
The extension prompts in Pi before contacting the daemon:
- TUI (
piin a terminal): an inline prompt in the editor slot (like ask-user-question) showsAllow pid to run <root command>?, the agent explanation,Agent says: Read only/Reversible/Changes files on your host, an optional warning, the host cwd and the complete command in a bordered block (PgUp/PgDn scrolls). Arrows choose, Enter selects, Escape denies. - RPC (pid VS Code sidebar): the extension calls
ctx.ui.selectwith a fixed title (<summary>\n\nCommand:\n<command>) and the optionsAllow once,Deny,Allow for this session. The pid sidebar recognises this during ahost_runcall and renders it in the same card format asask_user_question, with the command in a selectable, scrollable monospace block and no custom answer row. Other RPC clients see an ordinary select dialog. - No UI (print/JSON mode): denied without contacting the daemon.
Root-command extraction skips initial assignments and shows sudo <cmd> for common sudo forms. The title is only a hint; always read the entire command.
Allow once is first and the default: Enter selects it. Deny is second. Escape, cancellation, a five-minute prompt timeout, abort or UI failure denies without contacting the daemon. Allow once authorises one call. Allow for this session authorises only the exact command string and requested cwd for the current extension load. Even whitespace changes prompt again. Description, impact and execution timeout are not part of the match.
Session grants live only in extension memory, capped at 2048 entries with oldest eviction. Restart, resume, new session, fork, switch, /reload or session shutdown starts a new approval scope. There is no persistent allowlist.
Security model and limitations
- Approval is client-asserted. The daemon executes any valid request carrying
approval; it cannot verify that a human saw a prompt. Anything in a connected sandbox can therefore run host commands without interaction, claim an impact, or forge a session token. The token is a scope identifier, not authentication. UsePID_HOSTRUN=0or stop the daemon if that trade-off is unacceptable. Directory/socket permissions restrict access to your user and its mapped containers, not to Pi alone. - The socket directory bind is read-only: connecting works on Linux, but sandbox processes cannot unlink or replace the socket through this mount. It mounts the directory, not an inode, so daemon restarts work without remounting. This still needs verification with your actual rootless Docker/user mapping.
- No execution on malformed requests, unknown versions, unknown fields, denial (handled in the extension) or failed pre-execution audit append. Commands containing hidden controls, bidi/format characters or NUL are rejected by the daemon, never silently changed (the prompt may already have been shown). Tabs/newlines are allowed in commands and shown unchanged. Description controls are stripped; the TUI shows command control characters as escapes and the sidebar renders text literally, never as markup. Unicode visual confusables remain possible.
- Warning heuristics flag
;,&, pipes, redirection, command substitution, backticks, newlines, sudo and rm, includingcurl | sh. They deliberately over-warn inside quotes and are not a shell parser or safety assessment. A simple-looking command can be destructive, call a malicious executable, expand variables or load changed files. Session approval does not pin executable/file contents, symlink targets, environment or external state. - The daemon runs with your full host rights, credentials and network. Approval is a deliberate sandbox escape. A granted command can modify the daemon, log, source, services or permission state. Do not run the daemon as root, and do not approve opaque commands. An impact label is only the agent's claim.
- Abort/disconnect and execution timeout kill the command's process group with SIGKILL, including ordinary children. The extension closes its connection immediately; server cancellation follows asynchronously. Side effects are not rolled back. A command can escape its group with
setsid, daemonise, use sudo or ask another service to do work. Those processes may survive; this is not process containment. Inherited output pipes cannot stall cancellation indefinitely; after shell exit they have a one-second drain deadline. - At most 32 concurrent connections; first frame deadline ten seconds; approved commands may run concurrently. There is no rate limit per session or persistent identity.
- Each output stream keeps the first 24000 bytes and at most 1000 lines, decoding invalid UTF-8 with replacement. Remaining output is drained and discarded, not written to disk.
truncatedreports loss. Output is untrusted command data and may include secrets or terminal escape characters; it is returned to Pi/the model. - Audit:
~/.local/state/pid-hostrun/audit.log, JSON lines, directory 0700, file 0600. Records include UTC timestamp, untrusted session identifier, exact command, requested/effective cwd, decision/status and exit code (null before execution). Approvals are logged before execution and outcomes afterwards. Denials/cancellation are logged; malformed frames have no validated request to audit. The log is append-only by convention, not tamper-proof or fsync-durable. Commands can contain secrets. It grows without automatic rotation; restart the daemon after operator-managed rotation. An error after execution may mean the command already ran: do not automatically retry it.
Protocol v2
AF_UNIX stream socket; UTF-8, one JSON object plus LF per frame. One request/result per connection, no streaming. A request frame is at most 65536 bytes including LF:
{"version":2,"type":"run","session":"pi-id:random-load-token","command":"printf hello","description":"Read host-only information for diagnosis.","impact":"read-only","approval":"once","cwd":"/home/alice/project","timeout_seconds":60}
Required: version integer 2, type run, nonblank session (max 200 Unicode characters), nonblank command (16384), nonblank description (2048), impact (read-only, reversible, changes-host), approval (once, session, session-match; audited, not verified). Version 1 requests are rejected with an update hint. Optional: cwd (4096 characters, absolute or empty), timeout_seconds (finite number 0.1 to 3600, default 60). Missing/empty/nonexistent cwd falls back to host HOME. Byte frame limits still apply to multibyte strings. Other fields, including env, are rejected. The daemon never substitutes or truncates commands to fit caps.
{"version":2,"type":"result","status":"completed","message":"","exit_code":0,"stdout":"hello","stderr":"","truncated":false}
Statuses: completed (including nonzero shell exit), denied, aborted, timeout, error. Exit code is an integer when available, otherwise null; negative values are signal numbers negated. Every result has message, stdout, stderr, truncated. The daemon itself no longer denies; the extension returns denied locally with denied by user, denied (prompt timed out) or a no-UI message. A missing/refused socket is reported locally by the extension as daemon not running.
Disconnect/EOF cancels pending or executing work. A client can alternatively send {"version":2,"type":"cancel"} plus LF on the same connection and await an aborted result. For fail-closed handling, any follow-up byte cancels; it cannot approve or mutate a request. Cancellation may race command completion. The extension uses disconnect on AbortSignal/shutdown and validates/caps daemon responses (400000 bytes). Its final safety deadline is 3960 seconds with the supported execution limits.
Automated tests
From the checkout with Node 24 and Python 3:
mkdir -p .test-tmp
TMPDIR="$PWD/.test-tmp" PYTHONDONTWRITEBYTECODE=1 npm test
# For development typechecking (dev dependencies only):
npm install --ignore-scripts
npm run typecheck
bash -n install.sh uninstall.sh
Python unittest covers the v2 protocol (required approval, v1 rejection), types/caps, cancel/disconnect, process execution, environment/cwd fallback, process-group cleanup, escaped pipe holders, truncation, audit failures/permissions, stale sockets/duplicate daemons and installation with fake systemctl. Node covers root extraction/warnings, the exact RPC title, the TUI popup component, deny/timeout/abort without daemon contact, no-UI denial, exact session grants and isolation, malformed daemon responses, and Allow once against the real Python daemon.
Verified in the headless sandbox: 18 Python tests, 17 Node tests, TypeScript 5.9 checking against Pi 1.5.2, and Bash syntax checks. The pid sidebar card is covered by pid's unit and Playwright tests. Real TUI rendering on a terminal and installation with a real user service are not verified here.
The companion launcher tests use fake Docker and real Bash argument builders:
cd /path/to/pid
python3 -m unittest tests.test_launcher_hostrun tests.test_workspace_launch tests.test_rpc_launch tests.test_session_launch -v
Required host manual checks (not verified in the headless sandbox)
- Start a new interactive pid, then repeat through a new sidebar (RPC) connection. Check
PID_HOSTRUN_SOCKETand thathost_runappears. Requestprintf 'hostrun manual test\\n'with an honest explanation. Confirm title, explanation, impact line, host cwd and the exact command in both UIs. Try a 2048-character explanation and a long multiline command; the options must remain reachable and the command fully viewable. - Press Escape (TUI) or Skip (sidebar): nothing must run. Note that pressing Enter immediately selects Allow once, so check the command before pressing it. Choose Allow once: get stdout and exit 0; repeat and confirm it prompts again.
- Choose Allow for this session: repeat the exact command/cwd without a prompt. Change whitespace or cwd: prompt again.
/reloador a new/resumed session must require fresh approval. - Check title extraction with
FOO=bar printf okandsudo -n true, and warnings withprintf one; printf twoandprintf x > /tmp/hostrun-manual-check(deny the latter). Description text<b>not markup</b>must display literally. - Wait out a prompt (five minutes) and confirm denial. Abort Pi while a prompt is open: it must close. Approve
sleep 30, then abort: its process group must die and an aborted audit entry appear. - Run
pi -p(print mode) asking for host_run: it must be denied without contacting the daemon. - Stop/restart the service while a container stays connected. Calls while stopped must fail clearly; calls after restart must work through the same mount. Verify unlinking the socket fails in the container. Check audit entries and permissions.
- Log out/in (or reboot a headless host with lingering enabled): check service startup and the journal. Run uninstall and confirm the service/source are removed but audit records remain.