Skip to content

feat: add managed sandbox lifecycle - #98766

Closed
steipete wants to merge 1 commit into
mainfrom
codex/managed-sandbox-lifecycle
Closed

steipete wants to merge 1 commit into
mainfrom
codex/managed-sandbox-lifecycle

Conversation

@steipete

@steipete steipete commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #98516

What Problem This Solves

Long-running digital-employee and team-operations sessions can need an isolated sandbox that persists across turns in the same owner scope, but still gets cleaned up deterministically when the owning session resets, is deleted, rolls over, or becomes stale. Before this change, session-scope sandbox ownership and cleanup semantics were not managed as one lifecycle, which made deterministic reuse and terminal cleanup harder to reason about for operators.

Why This Change Was Made

This adds an opt-in managed lifecycle for ephemeral session-owned sandboxes using the existing sandbox backend, Docker, registry, workspace, and reset/session primitives. The implementation records lifecycle ownership, locks scope cleanup, reuses the same sandbox inside the owner scope, blocks conflicting reset/delete/compaction work while cleanup is pending, removes terminal runtime/workspace resources, and keeps idle/age pruning as crash-recovery retry behavior.

AI-assisted implementation disclosure: this draft was prepared with AI assistance. No transcript attachment is included.

User Impact

Operators can enable session-scoped sandboxing for long-running agents and expect stable reuse within a session owner plus deterministic cleanup on reset/delete/rollover. Sandboxing remains opt-in; this does not introduce a global default sandbox requirement or a breaking runtime default.

Evidence

Risks / Non-goals

  • Main advanced after the one requested local rebase; this draft intentionally does not chase unrelated main commits.
  • Required CI may inherit the current-main daemon-install-helpers test-type failure until main is fixed.
  • No UI or visual surface changed; no screenshots are applicable.
  • This does not change the global sandbox default.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime docker Docker and sandbox tooling agents Agent runtime and tooling extensions: codex extensions: openshell size: XL maintainer Maintainer-authored PR labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 24, 2026, 8:45 AM ET / 12:45 UTC.

ClawSweeper review

What this changes

This PR adds an opt-in prune.onSessionEnd setting to reuse session-scoped sandboxes while active and clean their runtime, browser, registry, and workspace state on session reset, deletion, or rollover.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 7 items remain

Keep open: this protected maintainer draft still owns the linked lifecycle feature, but it is dirty against current main and lacks current-head final-effect proof that an old owner cannot delete a new owner’s sandbox.

Priority: P2
Reviewed head: 165e68ca00cb5d144b587654ac82f0ce4fad9c11
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation has useful lifecycle coverage and prior Docker evidence, but current-main integration and authorization final-effect proof remain unresolved.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the linked Docker run is for pre-rebase head 87ac766 and proves allowed cleanup only; add redacted current-head output showing cleanup succeeds for the ending owner and leaves a different owner’s runtime and workspace intact before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: the linked Docker run is for pre-rebase head 87ac766 and proves allowed cleanup only; add redacted current-head output showing cleanup succeeds for the ending owner and leaves a different owner’s runtime and workspace intact before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main incompatibility: Current main records a Podman engine target in sandbox registry rows, while this branch's expanded registry entry omits that field; current main's backend manager requires it before managing Podman runtimes.
Authority-bearing cleanup path: The branch derives terminal cleanup from persisted owner session IDs and then removes runtime and workspace resources, making owner isolation a final-effect security boundary.
Current main lacks the proposed lifecycle option: Current main's sandbox prune settings contain idle and age thresholds but no session-end cleanup option, so the central feature is not implemented on main.
Findings None None.
Security Needs attention Prove different-owner rejection before cleanup I/O: The lifecycle function expands cleanup scopes from persisted owner IDs and then deletes runtimes and workspaces; attach production-boundary evidence that a stale owner cannot remove resources now owned by another session.

How this fits together

Sandbox configuration creates a runtime and workspace keyed to a session owner. Session lifecycle handlers and stale pruning later coordinate resource removal while locks and registry rows protect reuse and cleanup retries.

flowchart LR
  Config[Sandbox lifecycle setting] --> Owner[Session owner]
  Owner --> Runtime[Runtime browser and workspace]
  Owner --> End[Reset delete or rollover]
  End --> Locks[Admission and scope locks]
  Locks --> Cleanup[Backend registry and workspace cleanup]
  Cleanup --> Retry[Pending cleanup or stale-prune recovery]
Loading

Decision needed

Question Recommendation
Should OpenClaw adopt prune.onSessionEnd and its public sandbox cleanup metadata as a supported opt-in lifecycle contract after the current-main rebase? Sponsor the refreshed lifecycle contract: Rebase onto current main, preserve current backend ownership data, and require allowed-owner plus different-owner final-effect proof before review resumes.

Why: This adds a durable operator configuration and plugin-facing contract around destructive session-owned resource cleanup; implementation evidence cannot decide the permanent product boundary.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the linked Docker run is for pre-rebase head 87ac766 and proves allowed cleanup only; add redacted current-head output showing cleanup succeeds for the ending owner and leaves a different owner’s runtime and workspace intact before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security concern: Prove different-owner rejection before cleanup I/O - The lifecycle function expands cleanup scopes from persisted owner IDs and then deletes runtimes and workspaces; attach production-boundary evidence that a stale owner cannot remove resources now owned by another session.
  • Resolve merge risk (P1) - A rebase must retain current main's recorded Podman engine target; otherwise cleanup and management of existing Podman runtimes can fail.
  • Resolve merge risk (P1) - The new persisted session-cleanup state, public SDK cleanup metadata type, and prune.onSessionEnd contract need fresh-install and upgrade coverage after rebasing.
  • Resolve merge risk (P1) - The branch has not shown current-head final-effect evidence that cleanup for a terminal owner cannot remove runtime or workspace resources reassigned to the nearest different owner.
  • Complete next step (P2) - A protected maintainer feature requires product sponsorship, conflict resolution against current main, and authority-boundary proof rather than an autonomous repair.

Findings

  • [medium] Prove different-owner rejection before cleanup I/O — src/agents/sandbox/lifecycle.ts:393
Agent review details

Security

Needs attention: Destructive cleanup is owner-authorized, but the current-head evidence does not prove that a different or reassigned owner is rejected before backend and filesystem removal.

PR surface

Source +3202, Tests +3927, Docs +63, Generated 0. Total +7192 across 69 files.

View PR surface stats
Area Files Added Removed Net
Source 43 3851 649 +3202
Tests 22 3991 64 +3927
Docs 3 63 0 +63
Config 0 0 0 0
Generated 1 2 2 0
Other 0 0 0 0
Total 69 7907 715 +7192

Review metrics

Metric Value Why it matters
Configuration and SDK surface 1 added config option, 1 exported SDK type The opt-in lifecycle changes both operator configuration and the plugin-facing cleanup contract.
Persisted session lifecycle state 3 added session-entry fields Reset and deletion now persist cleanup retries and owner IDs, so upgrade behavior needs explicit validation.

Stored data model

Persistent data-model change detected: serialized state: src/auto-reply/reply/session.test.ts, serialized state: src/auto-reply/reply/session.ts, serialized state: src/config/sessions/session-accessor.ts, serialized state: src/config/sessions/store.ts, serialized state: src/config/sessions/types.ts, serialized state: src/gateway/server-methods/sessions.ts, and 10 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #98516
Summary: This PR is the proposed implementation for the canonical managed session-sandbox lifecycle request; sandbox workspace pruning overlaps but remains a distinct reported behavior.

Members:

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

Merge-risk options

Maintainer options:

  1. Refresh and prove the lifecycle (recommended)
    Rebase onto current main, preserve Podman registry ownership, and attach redacted current-head Docker evidence for both the allowed owner and a different owner.
  2. Pause the new lifecycle contract
    Keep existing pruning behavior if maintainers do not want a persistent session-cleanup setting and SDK metadata contract.

Technical review

Best possible solution:

Rebase the lifecycle design onto current main, preserve its backend-target contract, then land only after the opt-in config and SDK contract are sponsored and real Docker evidence proves both allowed cleanup and forbidden-owner preservation.

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

Not applicable as a bug report: this is a new opt-in lifecycle feature. The supplied prior Docker run demonstrates some behavior, but not the current head or the forbidden-owner case needed for merge evidence.

Is this the best way to solve the issue?

No: the lifecycle shape is plausible, but the dirty base omits current main's Podman ownership contract and the destructive owner boundary remains unproven on the reviewed head.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The opt-in feature has bounded but consequential effects on sandboxed session operations.
  • merge-risk: 🚨 compatibility: The branch adds a documented config setting and SDK type while current main has incompatible registry ownership data.
  • merge-risk: 🚨 session-state: It persists cleanup markers and owner IDs across reset, deletion, rollover, and retries.
  • merge-risk: 🚨 security-boundary: Persisted owner identity controls destructive cleanup of sandbox runtimes and workspaces.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the linked Docker run is for pre-rebase head 87ac766 and proves allowed cleanup only; add redacted current-head output showing cleanup succeeds for the ending owner and leaves a different owner’s runtime and workspace intact before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Prove different-owner rejection before cleanup I/O — src/agents/sandbox/lifecycle.ts:393
    The lifecycle function expands cleanup scopes from persisted owner IDs and then deletes runtimes and workspaces; attach production-boundary evidence that a stale owner cannot remove resources now owned by another session.
    Confidence: 0.9

What I checked:

  • Current-main incompatibility: Current main records a Podman engine target in sandbox registry rows, while this branch's expanded registry entry omits that field; current main's backend manager requires it before managing Podman runtimes. (src/agents/sandbox/registry.ts:17, e30279f89ff5)
  • Authority-bearing cleanup path: The branch derives terminal cleanup from persisted owner session IDs and then removes runtime and workspace resources, making owner isolation a final-effect security boundary. (src/agents/sandbox/lifecycle.ts:393, 165e68ca00cb)
  • Current main lacks the proposed lifecycle option: Current main's sandbox prune settings contain idle and age thresholds but no session-end cleanup option, so the central feature is not implemented on main. (src/config/types.sandbox.ts:98, e30279f89ff5)
  • Feature-history routing: Current-main blame attributes the sandbox registry and prune baseline to Peter Steinberger, while the proposed lifecycle service is introduced by this PR head. (src/agents/sandbox/registry.ts:1, 3e5b935edf3f)
  • Proof does not cover the reviewed head or denied owner: The PR body links a Docker lifecycle run for pre-rebase head 87ac766; it shows reuse and removal, but not current-head behavior or rejection of cleanup for a different owner session. (87ac76653d21)
  • Current merge state: The supplied PR state reports this draft as dirty against main, so its lifecycle implementation must be rebased and re-reviewed before merge. (165e68ca00cb)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main while preserving the recorded Podman engine target through registry updates and cleanup.
  • Add final-effect proof for the nearest unauthorized principal and, when authority persists, prove reassignment invalidates it before I/O.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

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

History

Review history (4 earlier review cycles)
  • reviewed 2026-07-01T21:51:28.325Z sha 87ac766 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-04T11:51:52.496Z sha 165e68c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T20:04:11.397Z sha 165e68c :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T16:30:13.062Z sha 165e68c :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 1, 2026
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (post #99816/#99817).

Conflict resolutions:

  • src/gateway/session-reset-service.ts: kept this branch's try-wrapped resetSessionEntryLifecycle (pending-marker persistence on cleanup failure) and grafted in main's new else-branch that rebinds CLI reseed receipts for subagent resets (rebindCliSessionReseedReceiptsForReset).
  • src/gateway/server-methods/chat.ts: merged imports — main's isReplyRunAbortableForSignal plus this branch's waitForReplyRunAdmissionBlockRelease.
  • src/auto-reply/reply/reply-run-registry.test.ts: both sides appended distinct suites at the same anchor (main's late-abort/terminal-failure tests, this branch's admission-block tests) — kept both.
  • Plugin-SDK API baseline regenerated.

Local proof on head 165e68c: pnpm tsgo clean; all 32 test files touched by this PR — 835 passed, 0 failed.

Remaining before merge per prior review: sandbox/session-owner security sign-off on sandbox.prune.onSessionEnd, destructive owner-matched cleanup semantics, and stale pending-marker recovery.

@steipete
steipete force-pushed the codex/managed-sandbox-lifecycle branch from 87ac766 to 165e68c Compare July 4, 2026 11:10
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 4, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 24, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Retiring this stale branch. Session-end sandbox destruction changes durable cleanup and reset/delete/rollover semantics across 69 files, and the sandbox registry and session owners have since moved (SQLite worker operations, #175837), so it conflicts. Idle and max-age pruning stay the supported cleanup.

Closed in a sweep of maintainer PRs open longer than a week. Reopen with a current reproduction if this still matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: codex extensions: openshell gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant