mastra-ai/mastra · error

Invalid mount path: ${mountPath}. Root path "/" is not allow

Error message

Invalid mount path: ${mountPath}. Root path "/" is not allowed.

What it means

After the character allowlist passes, validateMountPath rejects the root path `/` itself. Mounting or unmounting the filesystem root is never allowed — it would shadow the entire sandbox filesystem. Only subdirectory mount points are valid.

Source

Thrown at packages/core/src/workspace/sandbox/local-sandbox.ts:69

 * `os.tmpdir` is `undefined`. Evaluating it at import time crashes Studio boot.
 * See https://github.com/mastra-ai/mastra/issues/18519.
 */
export function getMarkerDir(): string {
  return path.join(os.tmpdir(), '.mastra-mounts');
}

/** Allowlist pattern for mount paths — absolute path with safe characters only. */
const SAFE_MOUNT_PATH = /^\/[a-zA-Z0-9_.\-/]+$/;

function validateMountPath(mountPath: string): void {
  if (!SAFE_MOUNT_PATH.test(mountPath)) {
    throw new Error(
      `Invalid mount path: ${mountPath}. Must be an absolute path with alphanumeric, dash, dot, underscore, or slash characters only.`,
    );
  }
  const segments = mountPath.split('/').filter(Boolean);
  if (segments.length === 0) {
    throw new Error(`Invalid mount path: ${mountPath}. Root path "/" is not allowed.`);
  }
  if (segments.some(seg => seg === '.' || seg === '..')) {
    throw new Error(`Invalid mount path: ${mountPath}. Path segments cannot be "." or "..".`);
  }
}

/** Canonicalize mount path so `/data`, `/data/`, `//data` all resolve to `/data`. */
function normalizeMountPath(mountPath: string): string {
  return `/${mountPath.split('/').filter(Boolean).join('/')}`;
}

// =============================================================================
// Local Sandbox
// =============================================================================

/**
 * Local sandbox provider configuration.
 */

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Mount at a specific subdirectory instead, e.g. `/data` or `/workspace`
  2. Add a pre-check: reject mountPath === '/' before calling mount/unmount
  3. Fix the config/env source so the mount point is a real named directory

Example fix

// before
const mountPath = process.env.MOUNT_PATH ?? '/';
sandbox.mount(mountPath);
// after
const mountPath = process.env.MOUNT_PATH || '/data';
if (mountPath === '/') throw new Error('Root path "/" is not an allowed mount point');
sandbox.mount(mountPath);
Defensive patterns

Strategy: validation

Validate before calling

if (mountPath === '/') throw new Error('Root path "/" is not an allowed mount point; use a named directory like /data');

Try / catch

try {
  await sandbox.mount(mountPath);
} catch (err) {
  if (/Root path/.test(String(err?.message))) {
    throw new Error(`MOUNT_PATH was '/'; set it to a real directory such as /data`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling `sandbox.mount('/')` or `sandbox.unmount('/')`; passing a variable that defaults to or resolves to `/` (e.g. an empty WORKDIR env var collapsed to root).

Common situations: Config value like `MOUNT_PATH=` falling back to `/`; mistakenly thinking mounting at root is a way to expose the whole host directory; programmatic path computation producing `/` after normalization.

Related errors


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