Skip to content

Sandbox zombie processes remain under PID 1 and accumulate until pids.max risk #68691

Closed

Description

@aaajiao

Summary

Sandbox sessions can accumulate zombie processes whose PPID is already 1, but they are not reaped by PID 1. Over time they stack up and can contribute to hitting the sandbox process limit (pids.max).

This does not look like a normal user-script leak anymore, because these are already orphaned zombies under PID 1.

Environment

  • OpenClaw: v2026.4.15
  • Runtime: sandboxed Docker session
  • Host: Linux arm64 / OrbStack VM on Apple Silicon

What I observed

Repeated checks inside the sandbox showed zombies like these:

count 23
10448	1	bash
23857	1	sh
44348	1	sh
52955	1	bash
74031	1	bash
74042	1	bash
74388	1	bash
75421	1	bash
83271	1	bash
84642	1	bash
90986	1	bash
98612	1	bash
106630	1	bash
124027	1	git
125371	1	bash
133905	1	git
146115	1	sort
146116	1	sort
146119	1	sort
146120	1	sort
146124	1	sort
146125	1	sort
150588	1	bash

Summary by command:

bash 13
sort 6
sh 2
git 2

Current process health at the time:

📊 Processes: 3 alive, 23 zombie, 26 total

Why this seems like a runtime / PID 1 issue

  • These are already zombies, so kill -9 is not meaningful.
  • Their PPID is already 1.
  • If PID 1 were reaping correctly, they should disappear.
  • Instead, they persist and accumulate.

That suggests the sandbox init / PID 1 / process supervision layer is not reaping all orphaned children.

Impact

  • Zombie count can keep climbing across normal tool/script usage.
  • This risks exhausting the sandbox process budget (pids.max).
  • Once process slots get tight, random commands, cron jobs, and tool executions can start failing in hard-to-explain ways.

We previously saw sandbox pressure around pids.max = 256, so this is not purely cosmetic.

Likely triggers

The zombies appear to come from normal shell-heavy activity, including things like:

  • bash / sh
  • shell pipelines involving sort
  • git
  • cron/script execution paths

So this may be reproducible with ordinary agent workloads, not only unusual manual commands.

Expected behavior

Orphaned zombie children adopted by PID 1 should be reaped promptly.

Actual behavior

Zombie processes with PPID=1 remain visible indefinitely and accumulate over time.

Optional follow-up

If useful, I can help capture a smaller repro focused on shell pipeline + orphaning behavior inside the sandbox.

Activity

  1. mjamiv commented on Apr 19, 2026

    @mjamiv
    Contributor

    Negative-repro datapoint to help bound this: a 2026.4.11 deployment running under a watchdog supervisor with gateway respawn disabled shows 0 PID-1 zombies after ~20h continuous uptime. If the original repro can be correlated with gateway respawn/restart churn rather than steady-state subprocess lifecycle, that may narrow the surface considerably.

  2. aaajiao commented on Apr 24, 2026

    @aaajiao
    ContributorAuthor

    Thanks, that datapoint is useful.

    One likely difference in our environment is that we make heavy use of sub-agents. My suspicion is that the resident zombies are mostly produced after sub-agent runs / sub-agent-adjacent shell activity, rather than by steady-state gateway uptime alone.

    So this may not reproduce on a quiet 2026.4.11 deployment with gateway respawn disabled, but may show up under normal agent workloads where sub-agents spawn shell-heavy tasks and then exit. In our case the zombies were already adopted by PID 1, so the issue looked less like an individual command leak and more like orphaned subprocesses from completed/aborted sub-agent work not being reaped.

    If helpful, I can try to capture a smaller repro around:

    1. run several sub-agent tasks that execute shell pipelines / git / sort
    2. wait for the sub-agent runs to finish
    3. inspect ps for STAT=Z with PPID=1
  3. aaajiao commented on Apr 25, 2026

    @aaajiao
    ContributorAuthor

    Additional observation from today:

    In the sandbox, PID 1 is currently sleep infinity, not an init/reaper process. All remaining zombies I inspected are already under PPID=1, so they cannot be cleared from userspace.

    One useful data point: I had a few orphaned python3 -m http.server preview processes. After terminating them, alive process count dropped, but zombie count increased (6 -> 9). So an automatic “kill orphan processes” health check can actually make the zombie count worse when PID 1 does not reap children.

    Current conclusion:

    • zombie accumulation is not always an immediate blocker at low counts;
    • but unreaped PPID=1 zombies persist until the sandbox/container is restarted;
    • shell-heavy workloads / detached launchers / sub-agent-heavy sessions can amplify the issue;
    • mitigation in userland should probably be read-only detection + reporting, not automatic killing;
    • the real fix likely needs the sandbox PID 1 / supervision layer to reap orphaned children, e.g. an init/reaper process.

    This narrows my earlier suspicion: sub-agents may be a workload amplifier, but the underlying issue is that orphaned children adopted by PID 1 are not being reaped.

  4. clawsweeper commented on Apr 30, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 28, 2026, 12:07 AM ET / 04:07 UTC.

    Summary
    Current main and the latest release still create Docker sandbox containers without --init and run sleep infinity as PID 1, so the reported PID-1 zombie accumulation remains valid. The direct init fix and the create-args hash rollout are already covered by open PRs, so this should stay open for maintainer coordination rather than another independent fix PR.

    Reproducibility: yes. for source reproduction: current main still runs Docker sandbox containers as sleep infinity without Docker --init, matching the reported unreaped PPID=1 zombie condition. I did not run a mutable long-duration Docker workload in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #68691
    Summary: This issue is the canonical open report for Docker sandbox PID-1 zombie reaping; related open PRs are fix candidates, while the merged runtime-image tini PR covers an adjacent but different Docker surface.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    Open PRs already cover the direct sandbox --init change and the hash rollout mechanism, so maintainers should review, coordinate, or replace that work instead of queueing another independent fix PR.

    Review details

    Best possible solution:

    Land a coordinated sandbox fix that runs Docker sandbox containers under an init/reaper process and includes a compatible recreate path for existing long-running containers.

    Do we have a high-confidence way to reproduce the issue?

    Yes for source reproduction: current main still runs Docker sandbox containers as sleep infinity without Docker --init, matching the reported unreaped PPID=1 zombie condition. I did not run a mutable long-duration Docker workload in this read-only review.

    Is this the best way to solve the issue?

    Yes in direction: the maintainable fix belongs at the sandbox container creation and reuse boundary, using Docker init plus create-args hash invalidation. Userland killing is not the best fix because the reporter observed it can increase zombies when PID 1 does not reap them.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • I did not run a live long-running Docker sandbox workload in this read-only review; the issue is source-reproducible and reporter-log-backed rather than locally live-reproduced here.
    • The likely fix changes Docker container creation flags, so maintainers still need upgrade proof that existing long-running sandbox containers recreate or otherwise receive the new PID-1 behavior.

    Codex review notes: model internal, reasoning high; reviewed against 1b0766080a30.

    Label changes

    Label justifications:

    • P1: The issue can exhaust sandbox process slots in long-running agent workloads and break normal tool execution.
    • impact:crash-loop: The reported zombie accumulation can lead to process-table exhaustion and sandbox command failures, which is a process-level availability risk.
    Evidence reviewed

    Acceptance criteria:

    • Review that sandbox create args include an init/reaper in src/agents/sandbox/docker.ts.
    • Prove existing long-running sandbox containers recreate or otherwise receive the new Docker flag when the flag lands.
    • Run focused sandbox coverage such as node scripts/run-vitest.mjs src/agents/sandbox-create-args.test.ts src/agents/sandbox/docker.config-hash-recreate.test.ts src/agents/sandbox/config-hash.test.ts.
    • Run real Docker sandbox proof showing PID 1 is an init/reaper and orphaned children do not remain as PPID=1 zombies.

    What I checked:

    • Repository policy read: Read the root and scoped agent AGENTS.md files; the root policy treats runtime defaults, setup/startup behavior, and compatibility-sensitive changes as maintainer-review surfaces, which matters for adding a Docker create flag to existing sandboxes. (AGENTS.md:1, 1b0766080a30)
    • Current sandbox create args lack Docker init: buildSandboxCreateArgs starts with docker create --name ... and appends labels, security, resource, and mount flags, but there is no --init flag in the current create-args path. (src/agents/sandbox/docker.ts:428, 1b0766080a30)
    • Current sandbox PID 1 command matches the report: The ordinary sandbox container path appends the image command sleep infinity, matching the reporter's observation that PID 1 is not an init/reaper process. (src/agents/sandbox/docker.ts:568, 1b0766080a30)
    • Existing-container rollout gap remains on main: The sandbox config hash inputs include Docker config, env policy, workspace, mount format, and browser security epoch, but no general Docker create-args epoch for flag-only changes. (src/agents/sandbox/config-hash.ts:17, 1b0766080a30)
    • Long-lived sandbox containers are a supported configuration: If both prune thresholds are zero, sandbox pruning returns without removing registry entries, so long-running agent/shared sandboxes can persist across normal use. (src/agents/sandbox/prune.ts:56, 1b0766080a30)
    • Docs expose the affected configuration surface: The sandbox config docs show scope: "agent", Docker pidsLimit: 256, and prune settings, which aligns with the issue's long-running sandbox plus process-limit risk. Public docs: docs/gateway/config-agents.md. (docs/gateway/config-agents.md:803, 1b0766080a30)

    Likely related people:

    • joshavant: Git blame and log show commit 6f10763 rewrote the current sandbox create, config-hash, and prune files now carrying the relevant docker create and sleep infinity paths. (role: recent area contributor; confidence: high; commits: 6f1076351cbe; files: src/agents/sandbox/docker.ts, src/agents/sandbox/config-hash.ts, src/agents/sandbox/prune.ts)
    • steipete: Sandbox history shows repeated work on container recreation, config hashing, pruning, Docker validation, and sandbox hardening around the affected lifecycle boundary. (role: feature history owner; confidence: high; commits: 79d8267413cc, 1835dec2004f, 5457f6e7e4ee; files: src/agents/sandbox/docker.ts, src/agents/sandbox/config-hash.ts, src/agents/sandbox/prune.ts)
    • dims: Commit fbf11eb added the sandbox browser security hash epoch pattern, which is the closest merged analogue for the create-args epoch needed by this issue's rollout path. (role: adjacent owner; confidence: medium; commits: fbf11ebdb711; files: src/agents/sandbox/browser.ts, src/agents/sandbox/config-hash.ts)
    • VintageAyu: Authored the merged Docker runtime-image tini fix, which resolves an adjacent PID-1 zombie surface but not the sandbox container creation path. (role: adjacent merged fix author; confidence: medium; commits: e096b296c383, e63e4f9551e9; files: Dockerfile, docs/install/docker.md, docs/install/fly.md)
    • luckylhb90: Opened the unmerged direct sandbox --init PR that targets the same PID-1 reaping issue; this is routing context rather than current-main ownership. (role: open fix candidate author; confidence: medium; commits: 51dbb5e8dba7; files: src/agents/sandbox/docker.ts, src/agents/sandbox-create-args.test.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  5. added
    P1
    impact:crash-loop
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    on May 19, 2026
  6. openclaw-barnacle commented on Jun 3, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  7. added
    stale
    on Jun 3, 2026
  8. added
    clawsweeper:no-new-fix-pr
    clawsweeper:fix-shape-clear
    clawsweeper:needs-maintainer-review
    on Jun 17, 2026
  9. steipete commented on Jul 10, 2026

    @steipete
    Contributor

    Fixed on main by #103441 in f698703934f.

    Docker now starts ordinary and browser sandbox containers with its built-in init process. A shared create-arguments epoch rolls the change out through both configuration hashes while preserving active containers and the existing explicit recreate hint. Real Docker proof showed the negative control retain one zombie, while the fixed path reported HostConfig.Init=true, PID 1 docker-init, and zero zombies after the same orphan-grandchild scenario. Cold recreation, hot deferral, 63 focused tests, and exact-head CI run 29072559013 passed.

  10. locked as resolved and limited conversation to collaborators on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clawsweeper:fix-shape-clearclawsweeper:needs-maintainer-reviewclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:crash-loopissue-rating: 🦞 diamond lobsterstale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions