Skip to content

Commit c99a72a

Browse files
欧阳claude
authored andcommitted
fix(sandbox): check for other sessions before deleting agent scope workspace
When pruning sandbox containers with agent scope, verify no other active sessions are using the same workspace directory before deleting it. This prevents data loss when multiple sessions share an agent workspace. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 798d0af commit c99a72a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/agents/sandbox/prune.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ async function pruneSandboxRegistryEntries<TEntry extends PruneableRegistryEntry
6666
if (params.cleanupWorkspace && params.cfg.scope !== "shared") {
6767
try {
6868
const scopeKey = resolveSandboxScopeKey(params.cfg.scope, entry.sessionKey);
69+
// For agent scope, verify no other sessions are using the same workspace
70+
if (params.cfg.scope === "agent") {
71+
const registry = await params.read();
72+
const otherSessionsActive = registry.entries.some(
73+
(e) =>
74+
e.containerName !== entry.containerName &&
75+
resolveSandboxScopeKey(params.cfg.scope, e.sessionKey) === scopeKey,
76+
);
77+
if (otherSessionsActive) {
78+
// Skip workspace cleanup - other sessions still using this workspace
79+
continue;
80+
}
81+
}
6982
const workspaceDir = resolveSandboxWorkspaceDir(params.cfg.workspaceRoot, scopeKey);
7083
await fs.rm(workspaceDir, { recursive: true, force: true });
7184
} catch {

0 commit comments

Comments
 (0)