Skip to content

Conversation

@ghostwriternr
Copy link
Member

Summary

  • Fix bug where child processes spawned with & inside bash -c "..." survived when parent was killed
  • Add comprehensive documentation for developers unfamiliar with bash
  • Update SESSION_EXECUTION.md to match current implementation

Changes

Bug Fix

Replaced set -m job control approach with /proc tree walking to kill all descendant processes. The previous approach failed for processes that spawn their own process groups (e.g., bash -c "sleep 100 &").

Documentation for Non-Bash Experts

Added to session.ts:

  • Bash concepts glossary (FIFOs, $!, $?, redirections, signals, etc.)
  • Linux process concepts (/proc filesystem, process tree killing)
  • Data flow diagrams for FIFO-based stdout/stderr separation
  • Annotated breakdown of the labeler pattern one-liner

Documentation Maintainability

  • Rewrote SESSION_EXECUTION.md to focus on architecture and design decisions
  • Added cross-references between doc and source code
  • Documented TypeScript patterns (shell death sentinel, hybrid detection, fallback chains)

Testing

  • All 493 unit tests pass
  • E2E process lifecycle tests pass

Replace process group kill with recursive /proc/PID/task/PID/children
traversal. This handles processes that spawn their own process groups
(e.g., children started with & inside bash -c). Removes set -m since
process groups are no longer used for killing.
Add comprehensive documentation for developers unfamiliar with bash:
- Glossary of bash concepts (FIFOs, backgrounding, redirections, etc.)
- Linux process concepts (/proc filesystem, process tree killing)
- Data flow diagrams for FIFO-based stdout/stderr separation
- Annotated breakdown of the labeler pattern one-liner
- Explanation of depth-first kill order for process trees
Update SESSION_EXECUTION.md:
- Rewrite to focus on architecture and design decisions
- Add tables for execution mode comparison
- Document process termination strategy (/proc tree walking)
- Add TypeScript patterns section (shell death sentinel, hybrid detection)
- Add cross-references to source files

Update session.ts:
- Add cross-reference to architecture doc in file header
- Document shellExitedPromise as 'sentinel Promise' pattern
- Clarify waitForExitCode detection strategy (4 mechanisms)
- Clarify waitForPidViaPipe fallback chain
@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2026

🦋 Changeset detected

Latest commit: b4d83ca

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/sandbox Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 13, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/sandbox-sdk/@cloudflare/sandbox@348

commit: b4d83ca

@github-actions
Copy link
Contributor

🐳 Docker Images Published

Default:

FROM cloudflare/sandbox:0.0.0-pr-348-5f750db

With Python:

FROM cloudflare/sandbox:0.0.0-pr-348-5f750db-python

With OpenCode:

FROM cloudflare/sandbox:0.0.0-pr-348-5f750db-opencode

Version: 0.0.0-pr-348-5f750db

Use the -python variant if you need Python code execution, or -opencode for the variant with OpenCode AI coding agent pre-installed.


📦 Standalone Binary

For arbitrary Dockerfiles:

COPY --from=cloudflare/sandbox:0.0.0-pr-348-5f750db /container-server/sandbox /sandbox
ENTRYPOINT ["/sandbox"]

Download via GitHub CLI:

gh run download 20957540665 -n sandbox-binary

Extract from Docker:

docker run --rm cloudflare/sandbox:0.0.0-pr-348-5f750db cat /container-server/sandbox > sandbox && chmod +x sandbox

@ghostwriternr ghostwriternr merged commit 6e164a4 into main Jan 13, 2026
12 of 13 checks passed
@ghostwriternr ghostwriternr deleted the fix/remove-set-m-job-control branch January 13, 2026 13:08
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.

1 participant