different-ai/openwork · error · InterpreterRuntimeError
Array.${name} is not available in CodeMode.
Error message
Array.${name} is not available in CodeMode. What it means
Only a fixed set of Array statics (isArray, of, from) is implemented in invokeArrayStatic. Any other Array.* static call hits the default branch and throws this error. The sandbox intentionally exposes a minimal, deterministic API surface.
Source
Thrown at packages/codemode/src/interpreter/runtime.ts:547
return Array.from((args[0] as SandboxMap).map.entries(), ([key, item]) => [key, item])
if (args[0] instanceof SandboxSet) return Array.from((args[0] as SandboxSet).set.values())
if (args[0] instanceof SandboxURLSearchParams) {
return Array.from(args[0].params.entries(), ([key, value]) => [key, value])
}
const source = boundedData(args[0], "Array.from input")
if (typeof source === "string") return Array.from(source)
if (Array.isArray(source)) return [...source]
if (
source !== null &&
typeof source === "object" &&
typeof (source as { length?: unknown }).length === "number"
) {
return Array.from(source as ArrayLike<unknown>)
}
throw new InterpreterRuntimeError("Array.from expects an array, string, Map, Set, or array-like value.", node)
}
default:
throw new InterpreterRuntimeError(`Array.${name} is not available in CodeMode.`, node)
}
}
const invokeGlobalMethod = (ref: GlobalMethodReference, args: Array<unknown>, node: AstNode): unknown => {
if (ref.namespace === "console")
throw new InterpreterRuntimeError(`console.${ref.name} is not available in CodeMode.`, node)
if (ref.namespace === "Object") return invokeObjectMethod(ref.name, args, node)
if (ref.namespace === "Math") return invokeMathMethod(ref.name, args, node)
if (ref.namespace === "Array") return invokeArrayStatic(ref.name, args, node)
if (ref.namespace === "Number") return invokeNumberStatic(ref.name, args, node)
if (ref.namespace === "String") return invokeStringStatic(ref.name, args, node)
if (ref.namespace === "URL") return invokeURLStatic(ref.name, args, node)
if (ref.namespace === "Date") {
if (!dateStatics.has(ref.name))
throw new InterpreterRuntimeError(`Date.${ref.name} is not available in CodeMode.`, node)
return invokeDateStatic(ref.name, args, node)
}
if (View on GitHub (pinned to 2b7df46e8a)
Solutions
- Restrict to Array.isArray, Array.of, and single-argument Array.from
- Fix typos (Array.form -> Array.from)
- Implement missing helpers manually with supported syntax (loops, spread)
- Perform unsupported operations via a tool call instead of inline CodeMode
Example fix
// before
const filled = Array.from({length: 3}, () => 0); // also rejected
const isArr = Array.instanceOf(x); // not a real API -> throws
// after
const isArr = Array.isArray(x); Defensive patterns
Strategy: try-catch
Validate before calling
const supportedArrayStatics = ['isArray','of','from'];
if (/Array\.[A-Za-z_$][\w$]*\s*\(/.test(code)) {
for (const m of code.matchAll(/Array\.([A-Za-z_$][\w$]*)\s*\(/g)) {
if (!supportedArrayStatics.includes(m[1])) throw new Error(`Array.${m[1]} unsupported in CodeMode`);
}
} Type guard
function arrayStaticSupported(name) { return ['isArray','of','from'].includes(name); } Try / catch
try {
result = invokeCodeMode(code);
} catch (e) {
if (String(e.message).startsWith('Array.')) {
// fall back to a host-side implementation of the static
} else throw e;
} Prevention
- Limit Array usage to isArray/of/from inside sandbox code
- Check for typos like Array.form
- Move exotic array statics into host-side tools
When it happens
Trigger: Calling unsupported Array statics inside CodeMode such as Array.fromAsync, Array.prototype-flavored statics like Array.flat (mistaken), or hypothetical Array.zip/pair helpers; any Array.<name> not matching isArray/of/from.
Common situations: Using newer or exotic Array statics; typos like Array.form instead of Array.from (hits default branch); assuming Node's full global Array surface exists in the sandbox.
Related errors
- String method '${name}' is not available in CodeMode.
- console.${ref.name} is not available in CodeMode.
- Date.${ref.name} is not available in CodeMode.
- ${ref.namespace}.${ref.name} is not available in CodeMode.
- RegExp method '${name}' is not available in CodeMode.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/9dc576cce87753e2.
Report an issue: GitHub.