Skip to content

[Bug]: Sandbox prune does not clean up workspace directory #43797

Closed as not planned
BingqingLyu/openclaw
#510

Description

@climbran

Bug type

Behavior bug (incorrect output/state without crash)

Summary

Sandbox prune removes Docker containers but leaves workspace directories behind, causing disk space leak over time

Steps to reproduce

  1. Configure an agent with sandbox.prune.idleHours or sandbox.prune.maxAgeDays (e.g., idleHours: 168)
  2. Wait for the sandbox to expire (or trigger prune manually via openclaw sandbox prune)
  3. Check ~/.openclaw/sandboxes/ - old directories remain
  4. Docker containers are removed, but the agent--xxxx directories persist

Expected behavior

Both Docker containers AND workspace directories (~/.openclaw/sandboxes/agent--xxxx) should be cleaned up when sandbox expires due to idleHours or maxAgeDays

Actual behavior

Only Docker containers are removed (via docker rm -f). The workspace directories in ~/.openclaw/sandboxes/ persist after prune. This causes disk space leak over time.

OpenClaw version

2026.3.8

Operating system

macOS 25.2.0 (arm64)

Install method

No response

Model

minimax/MiniMax-M2.5

Provider / routing chain

minimax-portal (direct)

Config file / key location

No response

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

Affected: Users with sandbox-enabled agents using prune settings
Severity: Medium (disk space leak)
Frequency: Always when sandbox expires
Consequence: Over time, ~/.openclaw/sandboxes/ fills up with orphaned directories, wasting disk space

Additional information

Source code location: src/agents/sandbox/prune.ts - the pruneSandboxRegistryEntries function only removes Docker containers and registry entries, but does not delete the workspace directory (~/.openclaw/sandboxes/agent--xxxx). Suggested fix: add fs.rm() to remove the sandbox workspace directory after container removal.

Activity

  1. added
    bug
    on Mar 12, 2026
  2. added
    bug:behavior
    on Mar 12, 2026
  3. climbran commented on Mar 12, 2026

    @climbran
    Author

    Additional context: This issue also affects configuration updates. Because the sandbox persists the workspace directory (~/.openclaw/sandboxes/agent--xxxx), changes to files like SOUL.md don't take effect even after gateway restart. Even manually removing Docker containers doesn't help - users must manually delete the sandbox directory to pick up config changes.

    This suggests we need either:

    1. A way to force refresh/recreate sandbox workspaces (e.g., openclaw sandbox rm --force <agentId>)
    2. Or a config option to always start fresh (skip persistent workspace)
  4. added a commit that references this issue on Mar 12, 2026
    703747d
  5. openclaw-barnacle commented on Apr 27, 2026

    @openclaw-barnacle

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

  6. added
    stale
    on Apr 27, 2026
  7. clawsweeper commented on Apr 27, 2026

    @clawsweeper
    Contributor

    Codex review: this still needs some work.

    Summary
    Keep open: current main and v2026.10.5 still retain copied local workspaces after runtime pruning, while related lifecycle work leaves existing agent-scoped retention unresolved.

    Reproducibility: Source establishes retained directories and reuse of existing bootstrap files; no live sandbox reproduction was run, and the reported sandbox prune subcommand does not exist in current CLI registration.

    Root-cause cluster
    Relationship: canonical
    Canonical: #43797
    Summary: This issue remains the focused tracker for copied workspace retention after runtime pruning; the open managed-lifecycle proposal overlaps only part of that behavior.

    Members:

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

    Maintainer decision needed

    • Question: Should idle or age expiry of existing agent-scoped runtimes also delete their copied local workspaces?
    • Recommendation: Preserve existing workspaces by default: Document durable agent-scoped files, provide an explicit reset path, and restrict automatic deletion to owners explicitly defined as disposable.
    • Why: Current documentation defines runtime cleanup, while copied workspaces contain writable user work and the open lifecycle proposal covers opt-in session ownership.

    Next step
    Decide existing agent-scoped workspace retention alongside #98766 before implementing automatic deletion.

    Review details

    Best possible solution:

    Define workspace retention explicitly, preserve durable work, and provide owner-controlled cleanup or reset with a prune-and-recreate regression.

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

    Source establishes retained directories and reuse of existing bootstrap files; no live sandbox reproduction was run, and the reported sandbox prune subcommand does not exist in current CLI registration.

    Is this the best way to solve the issue?

    Unconditional fs.rm after runtime removal is insufficient because runtime expiry does not establish that copied workspace contents are disposable.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Automatic deletion on runtime expiry could erase intentionally retained agent work; the disposable-workspace boundary remains undecided.

    Codex review notes: model internal, reasoning medium; reviewed against 7f902d4b3873.

    Label changes

    Label changes:

    • remove clawsweeper:needs-maintainer-review: Current issue advisory state no longer selects this label.

    Label justifications:

    • P2: Retained sandbox directories are a bounded operator problem without evidence of an urgent outage.
    • impact:session-state: Recreated runtimes can reuse copied bootstrap files and workspace state from the previous runtime.
    • impact:other: Retained copied workspace directories continue consuming local disk space.
    Evidence reviewed

    What I checked:

    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; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed October 19, 2026, 2:24 PM ET / 18:24 UTC.

  8. 60 remaining items

  9. added
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    clawsweeper:needs-product-decision
    and removed
    clawsweeper:needs-live-repro
    issue-rating: 🐚 platinum hermit
    on Jul 31, 2026
  10. jinngimk-lang commented on Aug 17, 2026

    @jinngimk-lang
  11. added
    clawsweeper:intake:bug
    and removed
    clawsweeper:needs-maintainer-review
    clawsweeper:intake:bug
    on Oct 19, 2026
  12. steipete commented on Oct 22, 2026

    @steipete
    Contributor

    Thanks for filing this. We're closing issues opened before April 2026 that no longer look actionable on current main.

    Sandbox runtimes and their pruning have been reworked since this was filed, and the openclaw sandbox prune command from the report no longer exists. Agent-scoped workspaces are intentionally kept so durable files survive runtime pruning. If disposable sandbox workspaces still pile up on a current release, please open a fresh issue with the config and the directories left behind.

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

    P2bugbug:behaviorclawsweeper:linked-pr-openclawsweeper:needs-product-decisionclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:otherimpact:session-stateissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions