openclaw/openclaw · error · Error

fs sandbox glob character class cannot match path separators

Error message

fs sandbox glob character class cannot match path separators.

What it means

Inside a glob character class '[...]', the compiler rejects '/' and empty (falsy) characters because a class must not match path separators — this keeps the single-segment-wildcard invariant so classes cannot cross directory boundaries. Triggered when char is undefined or '/'.

Source

Thrown at extensions/codex/src/app-server/sandbox-exec-server/fs-policy.ts:331

  let index = startIndex + 1;
  if (index >= pattern.length) {
    throw new Error("fs sandbox glob character class must be closed.");
  }
  const negated = pattern[index] === "!" || pattern[index] === "^";
  if (negated) {
    index += 1;
  }
  let body = "";
  for (; index < pattern.length; index += 1) {
    const char = pattern[index];
    if (char === "]" && body) {
      return {
        source: `[${negated ? "^" : ""}${body}]`,
        endIndex: index,
      };
    }
    if (!char || char === "/") {
      throw new Error("fs sandbox glob character class cannot match path separators.");
    }
    body += escapeSandboxGlobCharacterClassChar(char, body.length === 0);
  }
  throw new Error("fs sandbox glob character class must be closed.");
}

function escapeSandboxGlobCharacterClassChar(char: string, first: boolean): string {
  if (char === "\\" || char === "]") {
    return `\\${char}`;
  }
  if (first && char === "^") {
    return "\\^";
  }
  return char;
}

function sandboxGlobLiteralPrefix(pattern: string): string {
  const wildcardIndex = pattern.search(/[*?[]/u);

View on GitHub (pinned to 01804a7531)

Solutions

  1. Remove '/' from inside character classes; use separate glob segments joined by '/' instead
  2. Replace a class that intends to match separators with a '**/' recursive wildcard
  3. Validate that no '[' ... ']' span in the pattern contains a '/' before sending

Example fix

// before: class contains a separator
{ pattern: '/src/[a/b]*' }

// after
{ pattern: '/src/[ab]/*' }
Defensive patterns

Strategy: validation

Validate before calling

function assertGlobClassNoSeparator(pattern: string): void {
  let inClass = false;
  for (const ch of pattern) {
    if (ch === '[') inClass = true;
    else if (ch === ']') inClass = false;
    else if (inClass && ch === '/') throw new Error('glob character class cannot contain /');
  }
}

Type guard

function globClassHasNoSeparator(pattern: string): boolean {
  let inClass = false;
  for (const ch of pattern) {
    if (ch === '[') inClass = true;
    else if (ch === ']') inClass = false;
    else if (inClass && ch === '/') return false;
  }
  return true;
}

Try / catch

try {
  resolveFsSandboxPolicy(execServer, record);
} catch (error) {
  if (error instanceof Error && error.message.includes('cannot match path separators')) {
    // split the class across segments or remove the '/'
  } else throw error;
}

Prevention

When it happens

Trigger: A glob like '/src/[a/b]' or '/[\/]bin' where a '/' appears inside the brackets; also when the iteration yields an empty character. The check fires before the character is appended to the class body.

Common situations: Attempting to match multiple path segments with a single class; copy-paste of regex into a glob; patterns that try to enumerate separator variants.

Related errors


AI-assisted analysis of openclaw/openclaw@01804a7531 (2026-08-12). Data as JSON: /api/errors/91203d546a5094a5. Report an issue: GitHub.