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

  1. Remove console.* calls and return the value instead (return data from the code)
  2. Collect messages into an array/string variable and return it for inspection
  3. 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

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


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