{"record":{"id":"a1f6df2712ef83d1","repo":"deepseek-ai/deepseek-harness","slug":"cannot-change-sandbox-mode-from-currentmode-t","errorCode":null,"errorMessage":"cannot change sandbox mode from \"${currentMode}\" to \"${event.data.mode}\" while persistent terminal sessions are open or being created; wait for creation to settle and close them first","messagePattern":"cannot change sandbox mode from \"(.+?)\" to \"(.+?)\" while persistent terminal sessions are open or being created; wait for creation to settle and close them first","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/terminal/terminal-bash/src/index.ts","lineNumber":50,"sourceCode":"\nconst sandboxModeFences = new WeakMap<Agent, SandboxModeFenceState>()\n\nfunction ensureSandboxModeFence(ctx: Context, owner: Agent): void {\n  const existing = sandboxModeFences.get(owner)\n  if (existing !== undefined) {\n    existing.pty = ctx.terminals\n    existing.sandboxPolicy = ctx.sandboxPolicy\n    return\n  }\n  const state: SandboxModeFenceState = { pty: ctx.terminals, sandboxPolicy: ctx.sandboxPolicy }\n  sandboxModeFences.set(owner, state)\n  owner.ctx.on('internal/dispatch', (_mode, eventName, args) => {\n    if (eventName !== 'session/event') return\n    const [session, event] = args as [Session, SessionEvent]\n    if (session !== owner.session || event.type !== 'sandbox/mode') return\n    const currentMode = effectiveSandboxMode(session.events) ?? state.sandboxPolicy.defaultMode\n    if (event.data.mode === currentMode || !state.pty.hasOwnerActivity(owner)) return\n    throw new Error(\n      `cannot change sandbox mode from \"${currentMode}\" to \"${event.data.mode}\" while persistent terminal sessions are open or being created; wait for creation to settle and close them first`,\n    )\n  }, { global: true })\n}\n\nfunction childEnvironment(spec: TerminalBackendSpawnSpec, dialect: ShellDialect): Record<string, string> {\n  // The subprocess provider supplies its own scrubbed ambient base; these are\n  // deliberate terminal-specific overrides layered after it.\n  const common = {\n    TERM: 'dumb',\n    PAGER: 'cat',\n    GIT_PAGER: 'cat',\n    DSH_SHELL: '1',\n    DSH_SESSION_ID: spec.owner.id,\n    DSH_PTY_SESSION_ID: spec.sessionId,\n  }\n  if (dialect === 'pwsh') {\n    // pwsh ignores PS1/PROMPT_COMMAND; its prompt is installed by the startup","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/terminal/terminal-bash/src/index.ts#L32-L68","documentation":"Error \"cannot change sandbox mode from \"${currentMode}\" to \"${event.data.mode}\" while persistent terminal sessions are open or being created; wait for creation to settle and close them first\" thrown in deepseek-ai/deepseek-harness.","triggerScenarios":"Thrown at packages/terminal/terminal-bash/src/index.ts:50 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wait for terminal creation to settle, close all open persistent sessions, then change the sandbox mode."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}