diff --git a/src/agents/sandbox/browser.ts b/src/agents/sandbox/browser.ts index 2a9d2370d1a..5ee35d088d7 100644 --- a/src/agents/sandbox/browser.ts +++ b/src/agents/sandbox/browser.ts @@ -141,11 +141,14 @@ export async function ensureSandboxBrowser(params: { return null; } - // Include workspaceDir in the slug so co-hosted instances with different HOME - // dirs produce distinct container names (fixes #51363). + // Include workspaceDir in the slug for shared/agent scopes so co-hosted + // instances with different HOME dirs produce distinct container names + // (fixes #51363). Session-scope containers are already collision-free via + // their per-session unique key, so we leave those names unchanged to avoid + // orphaning existing containers on upgrade. const slug = slugifySessionKey( - params.cfg.scope === "shared" - ? `shared:${params.workspaceDir}` + params.cfg.scope === "session" + ? params.scopeKey : `${params.scopeKey}:${params.workspaceDir}`, ); const name = `${params.cfg.browser.containerPrefix}${slug}`; diff --git a/src/agents/sandbox/docker.ts b/src/agents/sandbox/docker.ts index 77d585b9aa1..2aafcca03cd 100644 --- a/src/agents/sandbox/docker.ts +++ b/src/agents/sandbox/docker.ts @@ -496,11 +496,14 @@ export async function ensureSandboxContainer(params: { cfg: SandboxConfig; }) { const scopeKey = resolveSandboxScopeKey(params.cfg.scope, params.sessionKey); - // Include workspaceDir in the slug so co-hosted instances with different HOME - // dirs produce distinct container names (fixes #51363). + // Include workspaceDir in the slug for shared/agent scopes so co-hosted + // instances with different HOME dirs produce distinct container names + // (fixes #51363). Session-scope containers are already collision-free via + // their per-session unique key, so we leave those names unchanged to avoid + // orphaning existing containers on upgrade. const slug = slugifySessionKey( - params.cfg.scope === "shared" - ? `shared:${params.workspaceDir}` + params.cfg.scope === "session" + ? scopeKey : `${scopeKey}:${params.workspaceDir}`, ); const name = `${params.cfg.docker.containerPrefix}${slug}`;