different-ai/openwork · error · InterpreterRuntimeError

String method '${name}' is not available in CodeMode.

Error message

String method '${name}' is not available in CodeMode.

What it means

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.

Source

Thrown at packages/codemode/src/interpreter/runtime.ts:507

      result = value.substr(optNum(0) ?? 0, optNum(1))
      break
    // JS charCodeAt returns NaN out of range; NaN flows as an ordinary in-sandbox value
    // (normalized to null only at the data boundary - see copyOut), so return it as-is.
    case "charCodeAt":
      result = value.charCodeAt(optNum(0) ?? 0)
      break
    case "codePointAt":
      result = value.codePointAt(optNum(0) ?? 0)
      break
    case "toString":
      result = value
      break
    case "concat": {
      result = value.concat(...args.map((_, index) => str(index)))
      break
    }
    default:
      throw new InterpreterRuntimeError(`String method '${name}' is not available in CodeMode.`, node)
  }
  return boundedData(result, `String.${name} result`)
}

const invokeArrayStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {
  switch (name) {
    case "isArray":
      return Array.isArray(args[0])
    case "of":
      return [...args]
    case "from": {
      if (args.length > 1) {
        throw new InterpreterRuntimeError(
          "Array.from(...) does not support a map function in CodeMode; call .map() on the result instead.",
          node,
          "UnsupportedSyntax",
          [supportedSyntaxMessage],
        )

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Replace the call with one of the supported methods (e.g. charAt, slice, substring, toUpperCase, toLowerCase, trim, includes, indexOf, split, replace, concat, repeat)
  2. Implement the missing behavior manually with supported primitives (e.g. pad via repeat + concat)
  3. Check the interpreter runtime source for the exact whitelist of supported String methods
  4. Use tools (e.g. a JS/regex tool call) outside CodeMode for the unsupported operation

Example fix

// before
const padded = code.padStart(8, '0');
// after
const padded = '0'.repeat(Math.max(0, 8 - code.length)) + code;
Defensive patterns

Strategy: try-catch

Validate before calling

// Whitelist check before relying on a string method in CodeMode
const supportedStringMethods = ['charAt','slice','substring','toUpperCase','toLowerCase','trim','includes','indexOf','split','replace','concat','repeat'];
function stringMethodIsSupported(name) { return supportedStringMethods.includes(name); }

Type guard

function hasStringMethod(v, m) { return typeof v === 'string' && supportedStringMethods.includes(m); }

Try / catch

try {
  result = invokeCodeMode(code);
} catch (e) {
  if (String(e.message).includes("is not available in CodeMode")) {
    // rewrite/flag the unsupported string method
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/81fdec486f27bd2d. Report an issue: GitHub.