A local-first multi-agent app development platform, built on PenguinHarness
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/scriptUserPromptHooktake 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
SandboxSettingssnapshot on the Session's row (mode, network, masked paths, writable temp), shared by its subagents, and reached core throughconfineSpawnalone, which now wraps everything core spawns for the Session: command subprocesses, hook scripts,stdioMCP 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.
runHookScripttookconfine?: (argv) => ConfinedSpawnand spawned the argv it returned, with the runner's environment entries laid over the script's.scriptStopHook,scriptPreToolUseHookandscriptUserPromptHooktook an options object,ScriptHookOptions:timeoutS,pathPrepend, aconfineSpawngetter re-read at every run, andscope: { workspaceDir, scratchpadDir }, plustriggerfor the user-prompt adapter.Agent.sessionHooksbound the Session's confiner and scope into every installed command, so a script was confined asnode <script>with its package directory as cwd. A confiner that threw failed the hook with asandbox: …error, recorded ashook failed: sandbox: …like any hook failure; the script did not run. - stdio MCP Servers.
McpToolProviderOptionsgainedconfineSpawnandscratchpadDir, which the Environment passes from its own; astdioServer's[command, ...args]went through the confiner before the transport was built, with the Server's working directory ascwdand 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 itserror_message), reported like any other, and the Server did not start. Servers overhttp/sseare not processes of this machine and were untouched. - File tools.
read_file,edit_fileandwrite_filenow do every file-system effect — stat, reads (the windowed text scan included), atomic writes, directory listings,realpath,readlink,mkdir, andread_file's download of an image URL — through a port (environment/tools/fs-port.ts,FsPort), handed to the tool asToolExecutionContext.fs, resolved on first use so a call that touches no file never consults the confiner;fs.sandboxedsays 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 asnode -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 onEnvironment.dispose. Errors keep theircodeacross 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 gainedscratchpadDir, and the server'sconfinerForput it into a new optional field of the plugin contract,SandboxPolicy.writableRoots. Underworkspace-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-initializationskill said that a hook runs under the Session's sandbox, and its hooks reference listed thesandbox: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
penguinCLI 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: undernonethat 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
stdioMCP 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
nodejsfails every hook and file operation until it is initialized again, and astdioServer runs only if its command exists in the distro. A conversation that needs them there runs with full access. - SDK:
EnvironmentConfig.sandboxPolicyandCreateAgentOptions.sandboxPolicydo not exist;confineSpawnis the one seam. Pass the formertimeoutSandpathPrependarguments ofscriptStopHook,scriptPreToolUseHookandscriptUserPromptHookas the fourth argument,{ timeoutS, pathPrepend }.