{"record":{"id":"81fdec486f27bd2d","repo":"different-ai/openwork","slug":"string-method-name-is-not-available-in-codemo","errorCode":null,"errorMessage":"String method '${name}' is not available in CodeMode.","messagePattern":"String method '(.+?)' is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/interpreter/runtime.ts","lineNumber":507,"sourceCode":"      result = value.substr(optNum(0) ?? 0, optNum(1))\n      break\n    // JS charCodeAt returns NaN out of range; NaN flows as an ordinary in-sandbox value\n    // (normalized to null only at the data boundary - see copyOut), so return it as-is.\n    case \"charCodeAt\":\n      result = value.charCodeAt(optNum(0) ?? 0)\n      break\n    case \"codePointAt\":\n      result = value.codePointAt(optNum(0) ?? 0)\n      break\n    case \"toString\":\n      result = value\n      break\n    case \"concat\": {\n      result = value.concat(...args.map((_, index) => str(index)))\n      break\n    }\n    default:\n      throw new InterpreterRuntimeError(`String method '${name}' is not available in CodeMode.`, node)\n  }\n  return boundedData(result, `String.${name} result`)\n}\n\nconst invokeArrayStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {\n  switch (name) {\n    case \"isArray\":\n      return Array.isArray(args[0])\n    case \"of\":\n      return [...args]\n    case \"from\": {\n      if (args.length > 1) {\n        throw new InterpreterRuntimeError(\n          \"Array.from(...) does not support a map function in CodeMode; call .map() on the result instead.\",\n          node,\n          \"UnsupportedSyntax\",\n          [supportedSyntaxMessage],\n        )","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/interpreter/runtime.ts#L489-L525","documentation":"CodeMode's interpreter implements only a whitelisted subset of String prototype methods in invokeStringMethod. When a string method call resolves to a name not in the switch's cases, the default branch throws this error instead of silently returning undefined. It indicates the method exists in JavaScript but is not exposed by the sandbox.","triggerScenarios":"Calling an unsupported String prototype method on a string value inside CodeMode code, e.g. 'abc'.padStart(5), 'x'.replaceAll('a','b'), str.at(-1), str.codePointAt(0), or localeCompare — any name that falls through the switch in invokeStringMethod, dispatched via invokeIntrinsic.","commonSituations":"Porting existing JavaScript snippets into CodeMode; assuming full ES spec coverage of String methods; using newer methods (replaceAll, at, padStart) that the sandbox hasn't whitelisted; generating code with an LLM that uses idiomatic JS string APIs.","solutions":["Replace the call with one of the supported methods (e.g. charAt, slice, substring, toUpperCase, toLowerCase, trim, includes, indexOf, split, replace, concat, repeat)","Implement the missing behavior manually with supported primitives (e.g. pad via repeat + concat)","Check the interpreter runtime source for the exact whitelist of supported String methods","Use tools (e.g. a JS/regex tool call) outside CodeMode for the unsupported operation"],"exampleFix":"// before\nconst padded = code.padStart(8, '0');\n// after\nconst padded = '0'.repeat(Math.max(0, 8 - code.length)) + code;","handlingStrategy":"try-catch","validationCode":"// Whitelist check before relying on a string method in CodeMode\nconst supportedStringMethods = ['charAt','slice','substring','toUpperCase','toLowerCase','trim','includes','indexOf','split','replace','concat','repeat'];\nfunction stringMethodIsSupported(name) { return supportedStringMethods.includes(name); }","typeGuard":"function hasStringMethod(v, m) { return typeof v === 'string' && supportedStringMethods.includes(m); }","tryCatchPattern":"try {\n  result = invokeCodeMode(code);\n} catch (e) {\n  if (String(e.message).includes(\"is not available in CodeMode\")) {\n    // rewrite/flag the unsupported string method\n  } else throw e;\n}","preventionTips":["Consult the interpreter's String method whitelist before writing sandbox code","Prefer core methods (slice, indexOf, split, concat) over newer ES APIs","Lint or review generated code for unsupported string methods before execution","Handle unsupported string ops with host-side tools"],"tags":["codemode","sandbox","string-methods","unsupported-api"],"backgroundTag":"unsupported-api-in-sandbox","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}