mastra-ai/mastra · error · WorkspaceError

INVALID_CONFIG

INVALID_CONFIG

Error message

Cannot use both "filesystem" and "mounts"

What it means

A Workspace can obtain its filesystem either from a single `filesystem` config or from `mounts` (which build a CompositeFilesystem), but not both — the two sources are mutually exclusive by design. The constructor validates this and throws `WorkspaceError` with code `INVALID_CONFIG` when both are supplied and mounts is non-empty.

Source

Thrown at packages/core/src/workspace/workspace.ts:613

    this.name = config.name ?? `workspace-${this.id.slice(0, 8)}`;
    this.createdAt = new Date();
    this.lastAccessedAt = new Date();

    this._config = config;

    if (typeof config.sandbox === 'function') {
      this._sandboxResolver = config.sandbox as WorkspaceSandboxResolver;
    } else {
      this._sandbox = config.sandbox;
    }
    this._sandboxCacheKey = config.sandboxCacheKey;
    this._dynamicSandboxInstructions = config.instructions?.dynamicSandbox ?? 'placeholder';

    // Setup mounts - creates CompositeFilesystem and informs sandbox
    if (config.mounts && Object.keys(config.mounts).length > 0) {
      // Validate: can't use both filesystem and mounts
      if (config.filesystem) {
        throw new WorkspaceError('Cannot use both "filesystem" and "mounts"', 'INVALID_CONFIG');
      }
      if (this._sandboxResolver) {
        throw new WorkspaceError(
          'Cannot use "mounts" with a dynamic sandbox resolver. ' +
            'Mounts are attached to a sandbox instance at construction time. ' +
            'Either pass a static sandbox instance, or have your resolver return a sandbox with its mounts already configured.',
          'INVALID_CONFIG',
        );
      }

      // Warn: contained: false is incompatible with mounts
      for (const [mountPath, fs] of Object.entries(config.mounts)) {
        if (fs instanceof LocalFilesystem && !fs.contained) {
          console.warn(
            `[Workspace] LocalFilesystem at mount "${mountPath}" has contained: false, which is incompatible with mounts. ` +
              `CompositeFilesystem strips mount prefixes and produces absolute paths (e.g. "/file.txt"), ` +
              `which a non-contained LocalFilesystem interprets as real host paths instead of paths ` +
              `relative to basePath. Use contained: true (default) or allowedPaths for specific exceptions.`,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Remove the `filesystem` property and keep `mounts` (mounting the primary filesystem at '/' if a root fs is needed)
  2. Or remove `mounts` and keep `filesystem` if a single filesystem suffices
  3. If merging configs, ensure only one of the two keys survives the merge

Example fix

// before
new Workspace({
  filesystem: new LocalFilesystem('/repo'),
  mounts: { '/data': new LocalFilesystem('/data') },
})

// after
new Workspace({
  mounts: {
    '/': new LocalFilesystem('/repo'),
    '/data': new LocalFilesystem('/data'),
  },
})
Defensive patterns

Strategy: validation

Validate before calling

if (cfg.filesystem && cfg.mounts && Object.keys(cfg.mounts).length > 0) {
  throw new Error('Workspace config cannot include both `filesystem` and non-empty `mounts`.');
}

Try / catch

try {
  const ws = new Workspace(cfg);
} catch (err) {
  if (err?.code === 'INVALID_CONFIG') {
    console.error('Workspace config error:', err.message);
    throw err;
  }
  throw err;
}

Prevention

When it happens

Trigger: `new Workspace({ filesystem: someFs, mounts: { '/data': otherFs } })` — any config where `config.filesystem` is set AND `config.mounts` has at least one key.

Common situations: Merging default config objects where a base config sets `filesystem` and an override adds `mounts`; copying example code that uses mounts into an existing config that already sets `filesystem`; incremental migration from single-fs to mounts config.

Related errors


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