{"record":{"id":"1212243f40826518","repo":"mastra-ai/mastra","slug":"sandbox-sandbox-id-default-cwd-probe-failed","errorCode":null,"errorMessage":"Sandbox '${sandbox.id}' default cwd probe failed (exit ${probe.exitCode}): ${probe.stderr.trim() || probe.stdout.trim() || 'empty output'}","messagePattern":"Sandbox '(.+?)' default cwd probe failed \\(exit (.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/sandbox/session-sandbox.ts","lineNumber":136,"sourceCode":"  repoFullName: string,\n): Promise<string> {\n  const entry = sessionSandboxes.get(sessionId);\n  if (entry?.workdir && entry.sandbox === sandbox) return entry.workdir;\n  const workdir =\n    deriveLocalWorkdir(sandbox, repoFullName) ?? remoteWorkdirFromHome(await probeHome(sandbox), repoFullName);\n  if (entry && entry.sandbox === sandbox) entry.workdir = workdir;\n  return workdir;\n}\n\n/** One `pwd` in the VM's default shell cwd — its home dir, by provider convention. */\nasync function probeHome(sandbox: WorkspaceSandbox): Promise<string> {\n  if (!sandbox.executeCommand) {\n    throw new Error(`Sandbox '${sandbox.id}' cannot resolve its workdir: no executeCommand implementation`);\n  }\n  const probe = await sandbox.executeCommand('pwd');\n  const home = probe.stdout.trim().split('\\n').pop()?.trim() ?? '';\n  if (probe.exitCode !== 0 || !home.startsWith('/')) {\n    throw new Error(\n      `Sandbox '${sandbox.id}' default cwd probe failed (exit ${probe.exitCode}): ${\n        probe.stderr.trim() || probe.stdout.trim() || 'empty output'\n      }`,\n    );\n  }\n  return home;\n}\n\n/**\n * The session's memoized sandbox (and its workdir) when one was already\n * constructed in this process, else undefined. Never constructs — passive\n * read paths use this so browsing files cannot provision a VM.\n */\nexport function peekSessionSandbox(sessionId: string): SessionSandboxEntry | undefined {\n  return sessionSandboxes.get(sessionId);\n}\n\n/** Drop the memoized instance (on stop/destroy/retirement or construction failure). */","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/sandbox/session-sandbox.ts#L118-L154","documentation":"probeHome() determines the sandbox VM's home directory by running `pwd` via the sandbox's executeCommand. If the command exits non-zero or the last stdout line is not an absolute path, the library throws because it cannot derive a remote workdir. This is a defensive check that the sandbox VM is actually up and behaving like a POSIX shell.","triggerScenarios":"Calling workdir() (or session setup flows that call it) on a remote WorkspaceSandbox whose executeCommand('pwd') returns a non-zero exit code, or returns stdout that does not end with an absolute path (e.g. empty or shell-banner output).","commonSituations":"VM not fully booted or paused when the probe runs; sandbox image lacks a shell or `pwd` binary; broken PATH inside the VM; provider auth expired so the exec API returns an error body; container restart leaving the default cwd unset.","solutions":["Verify the sandbox VM is running and ready before calling workdir() (await sandbox start/health).","Run a manual executeCommand('pwd') and inspect exitCode/stderr/stdout to see the provider's error message shown in this error.","Check sandbox provider credentials and network reachability (the stderr often contains an auth or DNS failure).","Confirm the sandbox image ships a POSIX shell with `pwd` available on PATH.","If stdout carries banner noise, ensure the last line is the absolute cwd path per provider convention."],"exampleFix":"// before: probing too early\nconst sandbox = createRemoteSandbox(opts);\nconst home = await probeHome(sandbox); // VM not ready -> exit code 1\n\n// after: wait for readiness first\nconst sandbox = createRemoteSandbox(opts);\nawait sandbox.waitForReady();\nconst home = await probeHome(sandbox);","handlingStrategy":"try-catch","validationCode":"// before resolving workdir\nif (!sandbox.executeCommand) throw new Error('sandbox has no executeCommand');\nconst probe = await sandbox.executeCommand('pwd');\nconst home = probe.stdout.trim().split('\\n').pop()?.trim() ?? '';\nconst sandboxReady = probe.exitCode === 0 && home.startsWith('/');\nif (!sandboxReady) console.error('sandbox not ready:', probe.stderr || probe.stdout);","typeGuard":"function isSandboxProbeOk(probe: { exitCode: number; stdout: string }): boolean {\n  const last = probe.stdout.trim().split('\\n').pop()?.trim() ?? '';\n  return probe.exitCode === 0 && last.startsWith('/');\n}","tryCatchPattern":"try {\n  const home = await workdir(sessionId, sandbox, repoFullName);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('default cwd probe failed')) {\n    // surface probe.exitCode/stderr, wait for VM readiness, then retry once\n    await sandbox.waitForReady?.();\n  } else throw err;\n}","preventionTips":["Await sandbox start/health checks before any workdir resolution.","Ensure the sandbox image ships a POSIX shell with pwd on PATH.","Monitor provider auth expiry and refresh credentials before exec calls.","Log probe stderr/stdout on failure — the message already embeds it for diagnosis."],"tags":["sandbox","remote-execution","shell-probe","infrastructure"],"backgroundTag":"sandbox-cwd-probe-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}