Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

7.5 KB
Raw Blame

The sandbox confines hook scripts, stdio MCP Servers and the file tools, with the scratchpad writable

  • Date: 2026-09-29
  • Type: feature
  • Scope: core, server, plugins, docs
  • PR: #893
  • Breaking: yes — in a confining sandbox mode the file tools and hook scripts are confined like commands and cannot write memory or Agent State; scriptStopHook / scriptPreToolUseHook / scriptUserPromptHook take an options object

中文版

The Session's sandbox policy, which had confined only the commands an agent runs, was extended to the hook scripts its Session runs, to the MCP Servers it starts over stdio, and to the file tools read_file, edit_file and write_file. Under workspace-write, the Session's scratchpad (<agent>/scratchpad/<session_id>, where the plan file, a goal's state file and the attachments live) became writable beside the Workspace and the temporary directory, for all three.

Details

  • One policy, one seam. The policy stayed the SandboxSettings snapshot on the Session's row (mode, network, masked paths, writable temp), shared by its subagents, and reached core through confineSpawn alone, which now wraps everything core spawns for the Session: command subprocesses, hook scripts, stdio MCP Servers and the file tools' helper. The confiner's answer for the helper's argv also decides whether a Session is confined at all: an answer that leaves the argv alone (the contract's word for "unconfined") keeps the file tools in-process.
  • Hook scripts. runHookScript took confine?: (argv) => ConfinedSpawn and spawned the argv it returned, with the runner's environment entries laid over the script's. scriptStopHook, scriptPreToolUseHook and scriptUserPromptHook took an options object, ScriptHookOptions: timeoutS, pathPrepend, a confineSpawn getter re-read at every run, and scope: { workspaceDir, scratchpadDir }, plus trigger for the user-prompt adapter. Agent.sessionHooks bound the Session's confiner and scope into every installed command, so a script was confined as node <script> with its package directory as cwd. A confiner that threw failed the hook with a sandbox: … error, recorded as hook failed: sandbox: … like any hook failure; the script did not run.
  • stdio MCP Servers. McpToolProviderOptions gained confineSpawn and scratchpadDir, which the Environment passes from its own; a stdio Server's [command, ...args] went through the confiner before the transport was built, with the Server's working directory as cwd and the Session's Workspace and scratchpad as scope, and the runner's environment entries lay over the Server's. A confiner that threw was that Server's connect failure (sandbox: … in its error_message), reported like any other, and the Server did not start. Servers over http / sse are not processes of this machine and were untouched.
  • File tools. read_file, edit_file and write_file now do every file-system effect — stat, reads (the windowed text scan included), atomic writes, directory listings, realpath, readlink, mkdir, and read_file's download of an image URL — through a port (environment/tools/fs-port.ts, FsPort), handed to the tool as ToolExecutionContext.fs, resolved on first use so a call that touches no file never consults the confiner; fs.sandboxed says which port it is. An unconfined Session's port is this process (localFsPort). A confined Session's is a helper process (environment/tools/fs-worker.ts): a Node process started as node -e <program> — the program travels inline, builtin modules only, so nothing ships beside a bundle — whose argv the confiner rewrote with the Session's Workspace and scratchpad as scope, serving the primitives as JSON lines over stdin and stdout, binary as base64. One helper serves a Session (SandboxedFsHost): started at the first confined file operation, reused afterwards, started over when the confiner's answer changes or after a crash, killed by an abort (the sandbox may be stalling the operation), stopped on Environment.dispose. Errors keep their code across the boundary, so the tools' diagnoses are unchanged; a permission error (EROFS / EACCES / EPERM) under a confining Session is reported as refused by the sandbox. Inside a Linux distro serving a Windows host (WSL), drive paths are mapped to /mnt/<drive> on the way in and back on the way out.
  • The scratchpad reached the backends. SpawnConfiner's options gained scratchpadDir, and the server's confinerFor put it into a new optional field of the plugin contract, SandboxPolicy.writableRoots. Under workspace-write, bwrap and Seatbelt added it to their writable roots, and WSL bound it into the distro at its translated path when the distro could reach it. A backend that ignores the field confines more narrowly, not more widely, so no dimension guards it.
  • Docs and skill. The Settings (Sandbox), Tools & Approval (File tools), The Agent Loop (Hooks), Skills & Plugins (Hook packages), Core Interfaces and Server Boot and Subsystems pages described the three executors, the writable directories and the new seams. The agent-initialization skill said that a hook runs under the Session's sandbox, and its hooks reference listed the sandbox: failure.

Not covered

  • Memory and Agent State (AGENTS.md, system_config.yaml, the vault, Skills, hook packages, scheduled tasks) stayed outside the writable directories of both confining modes. A confined agent could not write memory, write its own Skills or hook packages, or change its configuration, and so could not add an MCP Server either; those took full access.
  • A change the injected penguin CLI makes through the server API (a scheduled task, a plugin install) travels over the network, not the file system, so only the network level bounds it: under none that route is closed.
  • The DSH adaptor passed DSH only the mode and the Workspace, so under DSH commands and hook scripts could not write the scratchpad.
  • The WSL distro's default package list gained nodejs, which runs hook scripts and the file tools' helper; the confinement check reports whether it is there. A distro initialized before has to be initialized again — until then hooks and file operations fail under it instead of running unconfined.

Compatibility

  • A Session whose policy confines has its file tools and hook scripts confined from their next call, open conversations included, and its stdio MCP Servers from their next start (a context open or a reconnect); a Server that writes outside the writable directories or needs a network the level cuts no longer connects there. Writes to memory, Skills, hook packages and the agent's configuration are refused; switch a conversation that needs them to full access with its Permissions button. Nothing changes for a Session whose sandbox is off.
  • Under DSH, hooks that write the scratchpad fail, goal mode's among them; under WSL, a distro initialized without nodejs fails every hook and file operation until it is initialized again, and a stdio Server runs only if its command exists in the distro. A conversation that needs them there runs with full access.
  • SDK: EnvironmentConfig.sandboxPolicy and CreateAgentOptions.sandboxPolicy do not exist; confineSpawn is the one seam. Pass the former timeoutS and pathPrepend arguments of scriptStopHook, scriptPreToolUseHook and scriptUserPromptHook as the fourth argument, { timeoutS, pathPrepend }.