Skip to content

[Feature]: Managed ephemeral sandbox lifecycle for session-owned work #98516

Open

Description

@steipete

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" or scope: "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

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.

Activity

  1. added
    maintainer
    on Jul 1, 2026
  2. clawsweeper commented on Jul 1, 2026

    @clawsweeper
    Contributor

    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

    • Add a screenshot or short recording showing the behavior.
    • Include the exact command, prompt, or workflow that triggered it.
    • Add expected vs actual behavior.

    Maintainer decision needed

    Question Recommendation
    Should OpenClaw adopt an opt-in core contract that deletes session-scoped sandbox runtimes and non-shared workspaces on session reset, deletion, rollover, and terminal child-session cleanup? Sponsor a narrow lifecycle contract: Define the owner events, protected shared resources, locking, failure retry, and migration/doctor behavior, then ask for a focused implementation and scenario proof.

    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:

    • The requested opt-in policy adds a compatibility-sensitive sandbox configuration and must define the upgrade, doctor, and default-off behavior before existing operators can rely on it.
    • Cleanup crosses session state, runtime registries, browser resources, and filesystem workspaces; an incomplete ownership or locking contract could remove an active resource or leave sensitive state behind.
    • The linked implementation PR is currently open, draft, and reported dirty against main, so its evidence does not yet establish a landable canonical implementation.

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

    Label changes

    Label changes:

    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • remove 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:

    • [medium] Define owner cleanup authority and exclusions
      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:

    • Open implementation candidate: The provided issue timeline and linked pull-request body show an open PR that uses GitHub closing syntax for this issue. An open candidate implementation is not a basis to close the issue before it merges; it instead makes review and product sponsorship the immediate path. (165e68ca00cb)
    • Current supported sandbox scope: Current documentation supports session scope as one sandbox container per session and documents sandbox prune configuration precedence, but it does not establish the requested reset/delete-owned cleanup policy as an existing contract. Public docs: docs/tools/multi-agent-sandbox-tools.md. (docs/tools/multi-agent-sandbox-tools.md:263, a079d79f2039)
    • Product-direction fit: VISION.md prioritizes security and safe defaults and lists better computer-use and agent-harness capabilities as a next priority, while also requiring strict scrutiny for new core config and runtime surface. That supports discussion, not automatic feature implementation. (VISION.md:246, a079d79f2039)
    • Related problem boundary: [Bug]: Sandbox prune does not clean up workspace directory #43797 concerns workspace removal after idle/max-age prune; this issue is broader and introduces owner-triggered lifecycle cleanup on reset, deletion, and terminal session paths.

    Likely related people:

    • steipete: Opened this lifecycle proposal and authored the open pull request that explicitly targets it; no current-main ownership history could be established from the read-only execution environment. (role: linked design and implementation author; confidence: medium; commits: 165e68ca00cb; files: src/agents/sandbox, src/gateway)
    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.
  3. added
    P2
    impact:security
    impact:session-state
    maturity:stable
    issue-rating: 🌊 off-meta tidepool
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    clawsweeper:needs-security-review
    on Jul 1, 2026
  4. added
    clawsweeper:linked-pr-open
    and removed
    maturity:stable
    on Jul 30, 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

    P2clawsweeper:linked-pr-openclawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:needs-security-reviewclawsweeper:no-new-fix-primpact:securityimpact:session-stateissue-rating: 🌊 off-meta tidepoolmaintainer

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions