Repository navigation
Description
Summary
Add an opt-in managed ephemeral sandbox lifecycle for long-running OpenClaw digital-employee and team-operations sessions. A session- or thread-owned sandbox should be created once, reused deterministically within that owner scope, cleaned up when the owner is idle or terminal, and rebuilt/reset through the existing sandbox runtime primitives.
Problem
OpenClaw already has sandbox scopes, runtime registries, idle/age pruning, and openclaw sandbox recreate. Those pieces are not yet tied together as a lifecycle contract for session-owned work:
scope: "session"gives deterministic reuse, but cleanup is mostly idle/age based.- Session reset/delete and terminal child-session cleanup do not have a documented sandbox-owner cleanup hook.
- Explicit rebuild/reset behavior exists, but the owner cleanup semantics are not tested as one unit.
- Local per-scope sandbox workspaces can outlive their owning session when only the runtime is removed.
This makes long-running, task-oriented agents harder to operate safely: a completed or reset owner may leave runtime/workspace state behind, while a still-active owner should keep reusing the same sandbox.
Proposed solution
Add a narrow opt-in lifecycle on top of current sandbox primitives:
- Use
scope: "session"as the owner boundary. - Add a documented lifecycle cleanup setting under sandbox prune policy, defaulting off.
- On session reset/delete, and on terminal child-session cleanup that deletes the child session, remove matching session-scoped sandbox runtimes, browser runtimes, registry entries, and non-shared sandbox workspaces.
- Keep idle/max-age pruning as crash-recovery and long-idle cleanup.
- Keep explicit rebuild/reset on
openclaw sandbox recreate --session <key>/--agent <id>/--all. - Do not change global defaults or make sandboxing mandatory.
Alternatives considered
- Reuse
scope: "agent"orscope: "shared": too broad for task/thread ownership because multiple conversations share state. - Manual Docker/SSH cleanup: easy to mismatch registry state, workspace paths, and browser runtimes.
- Add a separate container lifecycle subsystem: unnecessary while the existing registry, backend manager, prune, and recreate paths can own this.
- Enable sandboxing by default: too broad for a focused lifecycle change.
Related OpenClaw context
- [Bug]: Sandbox prune does not clean up workspace directory #43797 tracks stale sandbox workspace cleanup after prune/recreate.
- [Bug] Subagent Docker containers not auto-removed after completion, causing maxConcurrent slot exhaustion #46254 documents current persistent-container expectations and why container count is not a concurrency limit.
- [Bug] Docker sandbox container name collision across multiple instances on same host #51363 tracks scope-key collisions across installs.
- Sandbox zombie processes remain under PID 1 and accumulate until pids.max risk #68691 tracks process cleanup inside long-lived Docker runtimes.
- agents.defaults.sandbox.mode is binary (all/none) — full bot outage when Docker briefly stops, including chat-only turns #80296 tracks lazy sandbox activation; this issue is about lifecycle ownership once sandboxing is enabled.
Impact
Operators can configure ephemeral session/thread sandboxes for long-running digital employees without losing deterministic reuse during the owner lifetime, and without leaving completed/reset owner state behind indefinitely.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jul 1, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 30, 2026, 4:34 PM ET / 20:34 UTC.
Summary
Keep open: this is a protected, security-sensitive core lifecycle feature request, and the linked implementation PR remains open rather than merged. The request needs an explicit maintainer decision on the durable sandbox-owner contract before any close or automated repair path. Likely related people: steipete, as the issue author and author of the linked implementation proposal (medium confidence).
Reproducibility: not applicable. as a feature request: the issue describes a desired lifecycle contract rather than a current-main failure with a defined expected behavior. Existing documentation confirms session-scoped sandbox reuse, but not the requested owner-triggered cleanup behavior.
Ways to help us reproduce this
Maintainer decision needed
Why: This changes a security boundary, adds configuration surface, and couples gateway session semantics to persistent backend and workspace cleanup; source-level mechanics cannot determine the intended product and upgrade contract.
Next step
The linked open PR and the required product/security contract make this unsuitable for an autonomous repair lane; maintainers need to decide the supported lifecycle boundary first.
Security
Needs attention: The requested lifecycle changes a sandbox isolation and deletion boundary, so authorization, lock ordering, retry behavior, and shared-resource exclusions require dedicated design review before implementation.
Review details
Best possible solution:
Agree on a narrow core-owned session-to-sandbox lifecycle contract, including authorization, locking, reset/delete ordering, shared-workspace exclusions, and upgrade behavior; then land a focused implementation with real Docker lifecycle proof and explicit operator documentation.
Do we have a high-confidence way to reproduce the issue?
Not applicable as a feature request: the issue describes a desired lifecycle contract rather than a current-main failure with a defined expected behavior. Existing documentation confirms session-scoped sandbox reuse, but not the requested owner-triggered cleanup behavior.
Is this the best way to solve the issue?
Unclear until maintainer intent is recorded. Reusing existing sandbox primitives is preferable to a parallel container manager, but the core owner-event, authorization, and upgrade contract must be settled before choosing an implementation shape.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against a079d79f2039.
Label changes
Label changes:
clawsweeper:linked-pr-open: Current issue advisory state selects this label.maturity:stable: Current issue review selected no maturity labels.Label justifications:
P2: This is a bounded but cross-cutting improvement to sandbox/session lifecycle behavior, with no confirmed active outage or data-loss incident.impact:session-state: The proposal changes cleanup semantics at session reset, deletion, rollover, and terminal child-session boundaries.impact:security: The requested behavior governs isolation resources, sandbox workspaces, and deletion of potentially sensitive runtime state.Evidence reviewed
Security concerns:
Session terminal events must only remove runtimes and workspaces proven to belong to that owner; shared scopes, adopted resources, and concurrent reset or compaction paths need an explicit protected contract.
Confidence: 0.9
What I checked:
docs/tools/multi-agent-sandbox-tools.md. (docs/tools/multi-agent-sandbox-tools.md:263, a079d79f2039)VISION.md:246, a079d79f2039)Likely related people:
src/agents/sandbox,src/gateway)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.