different-ai/openwork · error · InterpreterRuntimeError
console.${ref.name} is not available in CodeMode.
Error message
console.${ref.name} is not available in CodeMode. What it means
console.* methods (log, error, warn, etc.) are not implemented in CodeMode at all. invokeGlobalMethod rejects any reference whose namespace is 'console' before dispatching to other namespaces. The sandbox has no I/O console, so all console access is an immediate error.
Source
Thrown at packages/codemode/src/interpreter/runtime.ts:553
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 (
ref.namespace === "RegExp" ||
ref.namespace === "Map" ||
ref.namespace === "Set" ||
ref.namespace === "URLSearchParams"
) {
throw new InterpreterRuntimeError(`${ref.namespace}.${ref.name} is not available in CodeMode.`, node)View on GitHub (pinned to 2b7df46e8a)
Solutions
- Remove console.* calls and return the value instead (return data from the code)
- Collect messages into an array/string variable and return it for inspection
- Use the host environment's tooling/observability rather than in-code logging
Example fix
// before
console.log('result:', data);
return data;
// after
return data; // inspect the returned value Defensive patterns
Strategy: validation
Validate before calling
if (/\bconsole\s*\./.test(code)) {
throw new Error('console.* is unavailable in CodeMode; return values instead of logging');
} Try / catch
try {
result = invokeCodeMode(code);
} catch (e) {
if (String(e.message).includes('console.')) {
// strip logging and re-run, or instruct the model to return values
} else throw e;
} Prevention
- Never use console.log in sandbox code; return data instead
- Accumulate diagnostics in an array and return it
- Add a lint/strip step for console.* before execution
- Instruct code-generating models that console is unavailable
When it happens
Trigger: Any console.log(...), console.error(...), console.warn(...), console.table(...) etc. inside CodeMode code, dispatched via invokeGlobalMethod from evaluateCallExpression.
Common situations: Debugging habits carried over from normal JS; LLM-generated code that logs progress; porting scripts that rely on console output for results.
Related errors
- String method '${name}' is not available in CodeMode.
- Array.${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/30569f293c4c89a0.
Report an issue: GitHub.