different-ai/openwork · error · InterpreterRuntimeError
RegExp method '${name}' is not available in CodeMode.
Error message
RegExp method '${name}' is not available in CodeMode. What it means
CodeMode exposes only a whitelist of RegExp instance methods (test, exec, toString). Any other member invoked on a RegExp value — e.g. compile or Symbol-based methods — is rejected by design to keep the sandbox surface small and auditable.
Source
Thrown at packages/codemode/src/stdlib/regexp.ts:68
}
export const invokeRegExpMethod = (
value: SandboxRegExp,
name: string,
args: Array<unknown>,
node: AstNode,
): unknown => {
switch (name) {
case "test":
return value.regex.test(coerceToString(args[0]))
case "exec": {
const matched = value.regex.exec(coerceToString(args[0]))
return matched === null ? null : matchToValue(matched)
}
case "toString":
return coerceToString(value)
default:
throw new InterpreterRuntimeError(`RegExp method '${name}' is not available in CodeMode.`, node)
}
}
import { type AstNode, InterpreterRuntimeError } from "../interpreter/model.js"
import { isBlockedMember, type SafeObject } from "../tool-runtime.js"
import { SandboxRegExp } from "../values.js"
import { coerceToString } from "./value.js"
View on GitHub (pinned to 2b7df46e8a)
Solutions
- Rewrite the logic using only the allowed methods: test, exec, toString.
- Recreate the pattern with new RegExp instead of calling compile().
- Use string methods (match/replace/split/search) with the pattern instead.
Example fix
// before
const re = /a/g
re.compile("b")
// after
const re = new RegExp("b", "g")
const ok = re.test("abc") Defensive patterns
Strategy: validation
Validate before calling
const allowed = new Set(["test", "exec", "toString"])
if (!allowed.has(methodName)) console.warn(`use only ${[...allowed]} on RegExp in CodeMode`) Type guard
const isAllowedRegExpMethod = (name) => ["test", "exec", "toString"].includes(name)
Try / catch
try { r = regex.compile(p) } catch { r = new RegExp(p) } Prevention
- Restrict regex usage to test/exec/toString in sandbox code
- Rebuild patterns with new RegExp instead of compile
- Check the CodeMode API whitelist when porting JS
When it happens
Trigger: Calling `regex.compile(...)` or any non-whitelisted method on a value produced by a /pattern/ literal or `new RegExp(...)` inside CodeMode.
Common situations: Porting regular JS code that uses full RegExp APIs into CodeMode; forgetting that the sandbox intentionally omits rarely-used RegExp methods.
Related errors
- String method '${name}' is not available in CodeMode.
- Array.${name} is not available in CodeMode.
- console.${ref.name} is not available in CodeMode.
- Date.${ref.name} is not available in CodeMode.
- ${ref.namespace}.${ref.name} is not available in CodeMode.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/6115b429ca92a366.
Report an issue: GitHub.