{"record":{"id":"6115b429ca92a366","repo":"different-ai/openwork","slug":"regexp-method-name-is-not-available-in-codemo","errorCode":null,"errorMessage":"RegExp method '${name}' is not available in CodeMode.","messagePattern":"RegExp method '(.+?)' is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/regexp.ts","lineNumber":68,"sourceCode":"}\n\nexport const invokeRegExpMethod = (\n  value: SandboxRegExp,\n  name: string,\n  args: Array<unknown>,\n  node: AstNode,\n): unknown => {\n  switch (name) {\n    case \"test\":\n      return value.regex.test(coerceToString(args[0]))\n    case \"exec\": {\n      const matched = value.regex.exec(coerceToString(args[0]))\n      return matched === null ? null : matchToValue(matched)\n    }\n    case \"toString\":\n      return coerceToString(value)\n    default:\n      throw new InterpreterRuntimeError(`RegExp method '${name}' is not available in CodeMode.`, node)\n  }\n}\nimport { type AstNode, InterpreterRuntimeError } from \"../interpreter/model.js\"\nimport { isBlockedMember, type SafeObject } from \"../tool-runtime.js\"\nimport { SandboxRegExp } from \"../values.js\"\nimport { coerceToString } from \"./value.js\"\n","sourceCodeStart":50,"sourceCodeEnd":75,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/regexp.ts#L50-L75","documentation":"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.","triggerScenarios":"Calling `regex.compile(...)` or any non-whitelisted method on a value produced by a /pattern/ literal or `new RegExp(...)` inside CodeMode.","commonSituations":"Porting regular JS code that uses full RegExp APIs into CodeMode; forgetting that the sandbox intentionally omits rarely-used RegExp methods.","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."],"exampleFix":"// before\nconst re = /a/g\nre.compile(\"b\")\n// after\nconst re = new RegExp(\"b\", \"g\")\nconst ok = re.test(\"abc\")","handlingStrategy":"validation","validationCode":"const allowed = new Set([\"test\", \"exec\", \"toString\"])\nif (!allowed.has(methodName)) console.warn(`use only ${[...allowed]} on RegExp in CodeMode`)","typeGuard":"const isAllowedRegExpMethod = (name) => [\"test\", \"exec\", \"toString\"].includes(name)","tryCatchPattern":"try { r = regex.compile(p) } catch { r = new RegExp(p) }","preventionTips":["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"],"tags":["codemode","regex","sandbox","unsupported-api"],"backgroundTag":"api-not-available-in-sandbox","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}