different-ai/openwork · error · InterpreterRuntimeError

Number.${name} is not available in CodeMode.

Error message

Number.${name} is not available in CodeMode.

What it means

CodeMode sandboxes the JS interpreter and only exposes a whitelisted subset of Number statics (parseInt, parseFloat, etc.). invokeNumberStatic throws this when a script calls a Number static method that is not in the allowed switch, so authors know the capability is intentionally unavailable rather than a bug.

Source

Thrown at packages/codemode/src/stdlib/number.ts:62

    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") {
        throw new InterpreterRuntimeError("Number.parseInt expects a numeric radix.", node)
      }
      return parseInt(coerceToString(value), radix)
    }
    case "parseFloat":
      return parseFloat(coerceToString(value))
    default:
      throw new InterpreterRuntimeError(`Number.${name} is not available in CodeMode.`, node)
  }
}
import { type AstNode, InterpreterRuntimeError } from "../interpreter/model.js"
import { boundedData, coerceToString } from "./value.js"

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Replace Number.isNaN(x) with x !== x or a typeof/JSON-based check allowed by the sandbox
  2. Replace Number.isFinite/Number.isInteger with typeof x === 'number' && Number.isFinite alternatives implemented via arithmetic, or guard with typeof checks
  3. Check the CodeMode stdlib docs for the supported Number statics list and rewrite the script accordingly
  4. If the static is broadly needed, add a case to invokeNumberStatic in packages/codemode/src/stdlib/number.ts and a test

Example fix

// before
if (Number.isNaN(value)) return 0
// after
if (typeof value !== 'number' || value !== value) return 0
Defensive patterns

Strategy: type-guard

Validate before calling

const allowedNumberStatics = new Set(['parseInt','parseFloat'])
if (!allowedNumberStatics.has(fnName)) throw new Error(`Number.${fnName} unsupported in CodeMode`)
if (typeof value !== 'number') throw new Error('expected number')

Type guard

const isCodeModeNumberStatic = (name: string): name is 'parseInt' | 'parseFloat' => ['parseInt','parseFloat'].includes(name)

Try / catch

try {
  Number[fnName](arg)
} catch (e) {
  if (e instanceof InterpreterRuntimeError && e.message.includes('Number.')) {
    // fall back to sandbox-safe arithmetic checks
  }
  throw e
}

Prevention

When it happens

Trigger: Calling any Number static not handled by invokeNumberStatic, e.g. Number.isNaN(x), Number.isFinite(x), Number.isInteger(x), Number.isSafeInteger(x), Number.EPSILON access, Number.parseFloat vs Number.parseFloat alias, Number.MAX_SAFE_INTEGER, or Number.fromString-style calls inside CodeMode scripts.

Common situations: Porting regular JS utilities into CodeMode scripts where Number.isInteger/isNaN were used for validation; polyfill-style code that assumes full ECMAScript statics; LLM-generated scripts using Number.isNaN because CodeMode disallows global isNaN.

Related errors


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