different-ai/openwork · error · InterpreterRuntimeError
Number method '${name}' is not available in CodeMode.
Error message
Number method '${name}' is not available in CodeMode. What it means
invokeNumberMethod supports a fixed switch of Number.prototype methods (toFixed, toPrecision, toString, etc.). Any other method name hits the default branch and throws this error. The library makes unsupported method surface explicit rather than allowing a runtime 'not a function' failure deep in sandbox code.
Source
Thrown at packages/codemode/src/stdlib/number.ts:36
break
case "toExponential":
result = value.toExponential(optNum(0))
break
case "toPrecision": {
const digits = optNum(0)
result = digits === undefined ? value.toString() : value.toPrecision(digits)
break
}
case "toString": {
const radix = optNum(0)
if (radix !== undefined && (radix < 2 || radix > 36)) {
throw new InterpreterRuntimeError("Number.toString radix must be between 2 and 36.", node)
}
result = value.toString(radix)
break
}
default:
throw new InterpreterRuntimeError(`Number method '${name}' is not available in CodeMode.`, node)
}
return boundedData(result, `Number.${name} result`)
}
export const invokeNumberStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {
const value = args[0]
switch (name) {
case "isInteger":
return Number.isInteger(value)
case "isFinite":
return Number.isFinite(value)
case "isNaN":
return Number.isNaN(value)
case "isSafeInteger":
return Number.isSafeInteger(value)
case "parseInt": {
const radix = args[1]
if (radix !== undefined && typeof radix !== "number") {View on GitHub (pinned to 2b7df46e8a)
Solutions
- Use supported methods only: toFixed, toPrecision, toString (see the switch in packages/codemode/src/stdlib/number.ts).
- For locale formatting, pre-format the string outside CodeMode or format manually with toFixed.
- For toExponential, approximate via toPrecision or implement conversion in sandbox JS.
Example fix
// before
const s = value.toLocaleString("de-DE")
// after
const s = value.toFixed(2).replace(".", ",") Defensive patterns
Strategy: validation
Validate before calling
const allowedNumberMethods = new Set(["toFixed", "toPrecision", "toString"])
if (!allowedNumberMethods.has(methodName)) throw new Error(`Number.${methodName} is not whitelisted in CodeMode`) Type guard
const isNumberMethod = (n: string): n is "toFixed" | "toPrecision" | "toString" => allowedNumberMethods.has(n)
Try / catch
try { return value[methodName](...args) } catch (e) { if (/is not available in CodeMode/.test(String(e))) return numberFallback(value, methodName, args); throw e } Prevention
- Restrict sandbox code to toFixed, toPrecision, and toString
- Replace toLocaleString with manual formatting (toFixed + string ops)
- Replace toExponential with toPrecision or a hand-rolled formatter
- Watch for typos in method names — the whitelist rejects unknown names explicitly
When it happens
Trigger: Calling unsupported Number.prototype methods on sandbox numbers, e.g. value.toLocaleString("de-DE"), value.toExponential(2), or typos like value.toFixd(2).
Common situations: Locale-aware formatting in generated code (toLocaleString) — CodeMode does not support it; porting numeric formatting code that used toExponential; simple typos in method names.
Related errors
- Math.${name} is not available in CodeMode.
- 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.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/0af45206adac0abd.
Report an issue: GitHub.