different-ai/openwork · error · InterpreterRuntimeError

URL method '${name}' is not available in CodeMode.

Error message

URL method '${name}' is not available in CodeMode.

What it means

Sandbox URL instance values support only toString and toJSON. Any other method call on a SandboxURL (e.g. url.hostname getters are fine as properties, but method invocations outside the whitelist) is rejected to keep the sandbox API minimal.

Source

Thrown at packages/codemode/src/stdlib/url.ts:86

export const urlArgument = (value: unknown, label: string): string =>
  value instanceof SandboxURL ? value.url.href : uriArgument(value, label)

export const invokeURLStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {
  if (!urlStatics.has(name)) throw new InterpreterRuntimeError(`URL.${name} is not available in CodeMode.`, node)
  if (args.length === 0) throw new InterpreterRuntimeError(`URL.${name} requires a URL argument.`, node).as("TypeError")
  const input = urlArgument(args[0], `URL.${name} input`)
  const base = args[1] === undefined ? undefined : urlArgument(args[1], `URL.${name} base`)
  try {
    const url = new URL(input, base)
    return name === "canParse" ? true : new SandboxURL(url)
  } catch {
    return name === "canParse" ? false : null
  }
}

export const invokeURLMethod = (value: SandboxURL, name: string, node: AstNode): string => {
  if (name === "toString" || name === "toJSON") return value.url.href
  throw new InterpreterRuntimeError(`URL method '${name}' is not available in CodeMode.`, node)
}
import { type AstNode, InterpreterRuntimeError, UriFunction } from "../interpreter/model.js"
import { SandboxURL } from "../values.js"
import { boundedData, coerceToString } from "./value.js"

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Use toString() or toJSON() to get the href string, then operate on the string.
  2. Access URL properties (href, host, pathname, etc.) directly instead of calling methods.
  3. Parse the href back with URL statics exposed by the sandbox if restructuring is needed.

Example fix

// before
const host = url.someHostMethod()
// after
const host = new URL(url.toJSON()).host
Defensive patterns

Strategy: validation

Validate before calling

if (typeof url.toString !== "function" || !["toString","toJSON"].includes(methodName)) throw new TypeError("only toString/toJSON available on sandbox URL")

Type guard

const isAllowedURLMethod = (name) => name === "toString" || name === "toJSON"

Try / catch

try { s = url.fancyMethod() } catch { s = url.toJSON() }

Prevention

When it happens

Trigger: Calling `url.someMethod()` on a SandboxURL where someMethod is not toString/toJSON — for example emulating WHATWG URL instance APIs from regular JS.

Common situations: Porting Node/browser URL-handling code into CodeMode that relies on full URL instance methods.

Related errors


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