You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(runtime): opt-in host shell for PHP process execution - #2644
Fixes#2635. Adds an opt-in runtime capability, runtime.hostProcess: "shell" (default none). When on, a php-wasm spawn handler runs PHP's exec()/proc_open() commands through the host /bin/sh -c. Commands receive the run's environment (DB_*, PATH, secretEnv targets) and a per-run host temp directory. That directory is mounted into PHP at the same path, used as PHP's temp dir, and removed with the run. With the capability off, Playground's sandboxed spawn handler stays installed and behaviour is unchanged. When on, the run records it in metadata, review risk flags and a lifecycle event. docs/recipe-contract.md documents the shared paths and the trust boundary.
What changed
Contract: new RuntimeHostProcessMode (none | shell). It is threaded through the runtime environment spec and normalizer, the WorkspaceRecipe runtime type, the JSON schema, and CLI recipe validation. It is also wired into the recipe-run environment mapping, the buildWordPressPhpunitRecipe builder and the recipe-build phpunit command.
Runtime: new host-process-spawn-handler.ts adapts Node child_process.spawn to the php-wasm contract: - emits spawn before exit; - streams stdin, stdout and stderr; - emits exit only after output is drained; - reports exit code 127 when exec fails. It does no command parsing and has no allowlist. One routing rule keeps Codebox's VFS-only /internal/shared/bin/php, used by PHPUnit process isolation, inside php-wasm.
Runtime: new host-process-execution.ts prepares, per run: - a host temp dir, mounted at the same path in PHP and set as sys_temp_dir and TMPDIR; - working-directory mappings; - the forwarded environment; - cleanup when the run ends.
Wiring: the CLI path passes a wpCodeboxHostProcess runCLI option. The regenerated @wp-playground/cli patch threads it into bootRequestHandler in the ESM worker threads (v1 and v2). Those workers import the handler by URL and wrap the sandboxed factory. The programmatic runner wraps sandboxedSpawnHandlerFactory the same way. When the option is absent, both paths are unchanged.
Evidence and docs: runs with the capability on record: - a runtime.host-process-execution lifecycle event; - a metadata.jsonhostProcessExecution block (schema wp-codebox/host-process-execution/v1) holding mode, temp dir, cwd mappings and env variable names only, never values; - a host-process-execution entry in review riskFlags. Docs: a 'Host Process Execution' section in docs/recipe-contract.md and the rationale in patches/README.md. Tests: a unit test and an end-to-end Playground PHPUnit integration test.
Verification
All gates passed on 203e8aff4bb0. Base main: gated on 470b3743deb3, target now 470b3743deb3, re-verified: no.
Attempt run ID: agent-task-65c82602-75fc-44c5-abd3-cba035edf56b-attempt-1-f2282ba7
Gate 1: tree 47fe18ccc693410663adfebfc42d86298834671d
Gate 2: tree 47fe18ccc693410663adfebfc42d86298834671d
Delivery
Delivered: Opt-in runtime.hostProcess: shell capability, default off with sandboxed behaviour unchanged
Delivered: Host /bin/sh -c spawn handler: run env, streamed stdin/stdout/stderr, exit status, spawn emitted before exit
Delivered: Path parity: identity-mounted per-run temp dir used as sys_get_temp_dir()/TMPDIR and cleaned up with the run; working directory mapped through mounts; shared paths documented
Delivered: Run evidence/receipt records that host process execution was enabled
Delivered: Trust boundary documented in docs/recipe-contract.md
Delivered: End-to-end Playground PHPUnit test, enabled and disabled
Not delivered: exec()/system()$result_code parity with native (php-wasm's popen path (js_popen_to_file) never records the child process, so pclose() loses the exit code for every spawn handler, the stock sandbox included. Output is correct, and proc_open()/proc_close() returns the host status. The limitation is documented and was not patched in php-wasm's generated runtime.)
Evidence
Limits: the Homeboy lint gate did not run locally because the nodejs extension is not installed; that gate is left to Homeboy. The full smoke and integration suites were not run. The CJS worker builds are not patched, since Codebox loads the ESM entry.
Main vs PR, main: runtime.hostProcess is rejected by the recipe schema (additionalProperties: false on runtime). In Playground, the acceptance pipeline goes to the sandboxed handler: no output and proc_close 127. The PR's disabled case exercises this same code path.
PR receipt checks: - metadata.json had hostProcessExecution.enabled=true and mode=shell. - files/review.jsonriskFlags included host-process-execution. - The shared temp dir no longer existed after the run.
PR with hostProcess: "shell": tests/playground-host-process-execution.integration.test.ts ran a real Playground PHPUnit run, 3/3 tests passed in about 16s. - exec('{ echo hi; false; echo "exit:$?"; } | tail -c 100') returned the native /bin/sh output hi\nexit:1, and proc_close returned 0. - A file written via tempnam(sys_get_temp_dir()) was read back by host cat, and $TMPDIR equalled sys_get_temp_dir(). - proc_open streamed stdin, stdout and stderr, and exit 7 returned 7.
PR with the capability off: the same pipeline gave no native output, proc_close returned 127, and no hostProcessExecution metadata was recorded.
The AI did the whole change: - traced the php-wasm and Playground CLI spawn-handler plumbing; - designed and implemented the opt-in capability, contract threading, host spawn handler, path parity, evidence recording and Playground CLI patch; - wrote the docs, unit test and end-to-end test; - found the php-wasm popen exit-code limitation with direct runtime probes, under the direction of the Cook requester. Homeboy reports controller verification separately from this account of the AI's work. A human reviews before merge.
Reviewed: runtime.hostProcess: "shell" is opt-in and defaults to none, so sandboxed behavior is unchanged unless a recipe enables it. When enabled, commands run through host /bin/sh -c with no parser or allowlist. The sandbox's own PHP binary still routes to the sandboxed handler, so PHPUnit process isolation keeps working. A per-run temp dir is identity-mounted as PHP's temp dir, and runs that enable it record hostProcessExecution and a host-process-execution risk flag. The Cook's end-to-end test returns native /bin/sh output for the grouped pipeline and reads a PHP-written temp file from the host; with the capability off, proc_close returns 127. CI is green except browser, which also fails on main. Next: the Homeboy WordPress extension enables this for review and gate runs, and the wpcomsh SQLImporterTest run on Lab is the final proof.
AI disclosure: Claude Opus (Pi, via Roadie) reviewed this PR. The implementation is Claude Opus 5.5 (Homeboy Cook, cook-heavy fallback route).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2635. Adds an opt-in runtime capability,
runtime.hostProcess: "shell"(defaultnone). When on, a php-wasm spawn handler runs PHP'sexec()/proc_open()commands through the host/bin/sh -c. Commands receive the run's environment (DB_*, PATH, secretEnv targets) and a per-run host temp directory. That directory is mounted into PHP at the same path, used as PHP's temp dir, and removed with the run. With the capability off, Playground's sandboxed spawn handler stays installed and behaviour is unchanged. When on, the run records it in metadata, review risk flags and a lifecycle event.docs/recipe-contract.mddocuments the shared paths and the trust boundary.What changed
RuntimeHostProcessMode(none|shell). It is threaded through the runtime environment spec and normalizer, theWorkspaceReciperuntime type, the JSON schema, and CLI recipe validation. It is also wired into the recipe-run environment mapping, thebuildWordPressPhpunitRecipebuilder and therecipe-build phpunitcommand.host-process-spawn-handler.tsadapts Nodechild_process.spawnto the php-wasm contract: - emits spawn before exit; - streams stdin, stdout and stderr; - emits exit only after output is drained; - reports exit code 127 when exec fails. It does no command parsing and has no allowlist. One routing rule keeps Codebox's VFS-only/internal/shared/bin/php, used by PHPUnit process isolation, inside php-wasm.host-process-execution.tsprepares, per run: - a host temp dir, mounted at the same path in PHP and set assys_temp_dirandTMPDIR; - working-directory mappings; - the forwarded environment; - cleanup when the run ends.wpCodeboxHostProcessrunCLI option. The regenerated@wp-playground/clipatch threads it intobootRequestHandlerin the ESM worker threads (v1 and v2). Those workers import the handler by URL and wrap the sandboxed factory. The programmatic runner wrapssandboxedSpawnHandlerFactorythe same way. When the option is absent, both paths are unchanged.runtime.host-process-executionlifecycle event; - ametadata.jsonhostProcessExecutionblock (schemawp-codebox/host-process-execution/v1) holding mode, temp dir, cwd mappings and env variable names only, never values; - ahost-process-executionentry in reviewriskFlags. Docs: a 'Host Process Execution' section indocs/recipe-contract.mdand the rationale inpatches/README.md. Tests: a unit test and an end-to-end Playground PHPUnit integration test.Verification
All gates passed on
203e8aff4bb0. Basemain: gated on470b3743deb3, target now470b3743deb3, re-verified: no.HOMEBOY_LINT_BASE=470b3743deb3132965f1008cb18f63e8c90d5286 homeboy --placement local review lint wp-codebox --path . --…: passed, 68294 ms; retained gate metadata.npm run build: passed, 546 ms; retained gate metadata.Cook run
agent-task-65c82602-75fc-44c5-abd3-cba035edf56bagent-task-65c82602-75fc-44c5-abd3-cba035edf56b-attempt-1-f2282ba747fe18ccc693410663adfebfc42d86298834671d47fe18ccc693410663adfebfc42d86298834671dDelivery
runtime.hostProcess: shellcapability, default off with sandboxed behaviour unchanged/bin/sh -cspawn handler: run env, streamed stdin/stdout/stderr, exit status, spawn emitted before exitsys_get_temp_dir()/TMPDIRand cleaned up with the run; working directory mapped through mounts; shared paths documenteddocs/recipe-contract.mdexec()/system()$result_codeparity with native (php-wasm's popen path (js_popen_to_file) never records the child process, sopclose()loses the exit code for every spawn handler, the stock sandbox included. Output is correct, andproc_open()/proc_close()returns the host status. The limitation is documented and was not patched in php-wasm's generated runtime.)Evidence
nodejsextension is not installed; that gate is left to Homeboy. The full smoke and integration suites were not run. The CJS worker builds are not patched, since Codebox loads the ESM entry.runtime.hostProcessis rejected by the recipe schema (additionalProperties: falseon runtime). In Playground, the acceptance pipeline goes to the sandboxed handler: no output andproc_close127. The PR's disabled case exercises this same code path.metadata.jsonhadhostProcessExecution.enabled=trueandmode=shell. -files/review.jsonriskFlagsincludedhost-process-execution. - The shared temp dir no longer existed after the run.hostProcess: "shell":tests/playground-host-process-execution.integration.test.tsran a real Playground PHPUnit run, 3/3 tests passed in about 16s. -exec('{ echo hi; false; echo "exit:$?"; } | tail -c 100')returned the native/bin/shoutputhi\nexit:1, andproc_closereturned 0. - A file written viatempnam(sys_get_temp_dir())was read back by hostcat, and$TMPDIRequalledsys_get_temp_dir(). -proc_openstreamed stdin, stdout and stderr, andexit 7returned 7.proc_closereturned 127, and nohostProcessExecutionmetadata was recorded.AI disclosure
Tool: Homeboy Cook. Agent: Homeboy (roadie). Model: roadie · route cook-heavy · served claude-opus-5-5. Cook time: 34m35s.
The AI did the whole change: - traced the php-wasm and Playground CLI spawn-handler plumbing; - designed and implemented the opt-in capability, contract threading, host spawn handler, path parity, evidence recording and Playground CLI patch; - wrote the docs, unit test and end-to-end test; - found the php-wasm popen exit-code limitation with direct runtime probes, under the direction of the Cook requester. Homeboy reports controller verification separately from this account of the AI's work. A human reviews before merge.
Refs #2635