xai-org/grok-build · error

invalid deny glob {glob:?}: {e}

Error message

invalid deny glob {glob:?}: {e}

What it means

`validate_deny_glob` compiles each deny glob with `globset::GlobBuilder` (literal_separator enabled) and returns this error if the pattern is syntactically invalid. This is an input-validation error: the sandbox refuse deny rules it cannot compile, since an uncompilable glob could silently fail to deny writes. The error names the offending glob and the globset parse error.

Source

Thrown at crates/codegen/xai-grok-sandbox/src/deny/glob.rs:145

        }
        if cc.get(j) == Some(&']') {
            anyhow::bail!("deny glob {glob:?}: a literal ']' as first class member is unsupported");
        }
        while j < cc.len() && cc[j] != ']' {
            if cc[j] == '[' {
                anyhow::bail!(
                    "deny glob {glob:?}: nested '[' / POSIX '[[:…:]]' classes are unsupported"
                );
            }
            j += 1;
        }
        // Unterminated class: let the globset build below report it uniformly.
        i = if j < cc.len() { j + 1 } else { cc.len() };
    }
    globset::GlobBuilder::new(glob)
        .literal_separator(true)
        .build()
        .map_err(|e| anyhow::anyhow!("invalid deny glob {glob:?}: {e}"))?;
    Ok(())
}

/// Push `c` as a regex literal, escaping it when it is a regex metacharacter.
#[cfg(all(feature = "enforce", target_os = "macos"))]
fn push_escaped_regex_literal(out: &mut String, c: char) {
    if matches!(
        c,
        '.' | '+' | '*' | '?' | '(' | ')' | '[' | ']' | '{' | '}' | '^' | '$' | '|' | '\\'
    ) {
        out.push('\\');
    }
    out.push(c);
}

/// Regex-escape every character of a literal path segment.
#[cfg(all(feature = "enforce", target_os = "macos"))]
fn escape_regex_literal_str(s: &str) -> String {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Read the inner `{e}` to see the exact position and nature of the glob syntax error.
  2. Fix the pattern — commonly close the `[...]` character class or remove the stray bracket.
  3. Test the corrected glob against expected paths with globset (or a quick unit test) before redeploying.
  4. Quote backslashes properly in TOML (use single-quoted literal strings '...') to avoid escape mangling.

Example fix

// before
write_deny = ['/tmp/[abc', '**/secrets']
// after
write_deny = ['/tmp/[abc]*', '**/secrets'] // closed character class
Defensive patterns

Strategy: validation

Validate before calling

fn check_deny_globs(globs: &[String]) -> Result<(), String> {
    for g in globs {
        globset::GlobBuilder::new(g)
            .literal_separator(true)
            .build()
            .map_err(|e| format!("invalid deny glob {g:?}: {e}"))?;
    }
    Ok(())
}
// run at startup/config load, before applying the sandbox

Try / catch

match validate_deny_glob(glob) {
    Ok(()) => {}
    Err(e) if e.to_string().starts_with("invalid deny glob") => {
        eprintln!("Fix the pattern in sandbox.toml: {e:#}");
        std::process::exit(2); // config error, not runtime
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: A deny glob in config or CLI flags contains invalid syntax such as an unterminated `[` character class, malformed `{a,b}` alternation, or a dangling escape.

Common situations: Typo in ~/.grok/sandbox.toml or .grok/sandbox.toml write_deny patterns; hand-written globs like `/tmp/[abc` ; shell-style patterns copied that globset rejects; escaping mistakes with `\` in TOML strings.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/d114f3dcb5ad75f9. Report an issue: GitHub.