mastra-ai/mastra · error

Sandbox '${sandbox.id}' default cwd probe failed (exit ${pro

Error message

Sandbox '${sandbox.id}' default cwd probe failed (exit ${probe.exitCode}): ${probe.stderr.trim() || probe.stdout.trim() || 'empty output'}

What it means

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.

Source

Thrown at mastracode/factory/src/sandbox/session-sandbox.ts:136

  repoFullName: string,
): Promise<string> {
  const entry = sessionSandboxes.get(sessionId);
  if (entry?.workdir && entry.sandbox === sandbox) return entry.workdir;
  const workdir =
    deriveLocalWorkdir(sandbox, repoFullName) ?? remoteWorkdirFromHome(await probeHome(sandbox), repoFullName);
  if (entry && entry.sandbox === sandbox) entry.workdir = workdir;
  return workdir;
}

/** One `pwd` in the VM's default shell cwd — its home dir, by provider convention. */
async function probeHome(sandbox: WorkspaceSandbox): Promise<string> {
  if (!sandbox.executeCommand) {
    throw new Error(`Sandbox '${sandbox.id}' cannot resolve its workdir: no executeCommand implementation`);
  }
  const probe = await sandbox.executeCommand('pwd');
  const home = probe.stdout.trim().split('\n').pop()?.trim() ?? '';
  if (probe.exitCode !== 0 || !home.startsWith('/')) {
    throw new Error(
      `Sandbox '${sandbox.id}' default cwd probe failed (exit ${probe.exitCode}): ${
        probe.stderr.trim() || probe.stdout.trim() || 'empty output'
      }`,
    );
  }
  return home;
}

/**
 * The session's memoized sandbox (and its workdir) when one was already
 * constructed in this process, else undefined. Never constructs — passive
 * read paths use this so browsing files cannot provision a VM.
 */
export function peekSessionSandbox(sessionId: string): SessionSandboxEntry | undefined {
  return sessionSandboxes.get(sessionId);
}

/** Drop the memoized instance (on stop/destroy/retirement or construction failure). */

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the sandbox VM is running and ready before calling workdir() (await sandbox start/health).
  2. Run a manual executeCommand('pwd') and inspect exitCode/stderr/stdout to see the provider's error message shown in this error.
  3. Check sandbox provider credentials and network reachability (the stderr often contains an auth or DNS failure).
  4. Confirm the sandbox image ships a POSIX shell with `pwd` available on PATH.
  5. If stdout carries banner noise, ensure the last line is the absolute cwd path per provider convention.

Example fix

// before: probing too early
const sandbox = createRemoteSandbox(opts);
const home = await probeHome(sandbox); // VM not ready -> exit code 1

// after: wait for readiness first
const sandbox = createRemoteSandbox(opts);
await sandbox.waitForReady();
const home = await probeHome(sandbox);
Defensive patterns

Strategy: try-catch

Validate before calling

// before resolving workdir
if (!sandbox.executeCommand) throw new Error('sandbox has no executeCommand');
const probe = await sandbox.executeCommand('pwd');
const home = probe.stdout.trim().split('\n').pop()?.trim() ?? '';
const sandboxReady = probe.exitCode === 0 && home.startsWith('/');
if (!sandboxReady) console.error('sandbox not ready:', probe.stderr || probe.stdout);

Type guard

function isSandboxProbeOk(probe: { exitCode: number; stdout: string }): boolean {
  const last = probe.stdout.trim().split('\n').pop()?.trim() ?? '';
  return probe.exitCode === 0 && last.startsWith('/');
}

Try / catch

try {
  const home = await workdir(sessionId, sandbox, repoFullName);
} catch (err) {
  if (err instanceof Error && err.message.includes('default cwd probe failed')) {
    // surface probe.exitCode/stderr, wait for VM readiness, then retry once
    await sandbox.waitForReady?.();
  } else throw err;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/1212243f40826518. Report an issue: GitHub.