Skip to content

feat(runtime): opt-in host shell for PHP process execution - #2644

Merged
chubes4 merged 1 commit into
mainfrom
fix/issue-2635-wp-codebox-2
Dec 5, 2026
Merged

chubes4 merged 1 commit into
mainfrom
fix/issue-2635-wp-codebox-2

Conversation

@chubes4

@chubes4 chubes4 commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

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.json hostProcessExecution 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.

  • 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.
  • repro: none (no repro gate was declared, so these gates do not prove the issue).
  • CI: pending

Cook run
  • Cook ID: agent-task-65c82602-75fc-44c5-abd3-cba035edf56b
  • 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.json riskFlags 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.

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

@chubes4
chubes4 marked this pull request as ready for review December 5, 2026 17:42
@chubes4

chubes4 commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator Author

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).

@chubes4
chubes4 merged commit 77e094f into main Dec 5, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Opt-in host shell for PHP process execution in trusted runs (exec/proc_open fidelity)

1 participant