{"record":{"id":"e236cb5c030b590a","repo":"different-ai/openwork","slug":"object-name-is-not-available-in-codemode","errorCode":null,"errorMessage":"Object.${name} is not available in CodeMode.","messagePattern":"Object\\.(.+?) is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/object.ts","lineNumber":9,"sourceCode":"import { type AstNode, InterpreterRuntimeError } from \"../interpreter/model.js\"\nimport { isBlockedMember } from \"../tool-runtime.js\"\nimport { isSandboxValue, SandboxMap, SandboxURLSearchParams } from \"../values.js\"\nimport { boundedData, coerceToString } from \"./value.js\"\n\nexport const objectStatics = new Set([\"keys\", \"values\", \"entries\", \"hasOwn\", \"assign\", \"fromEntries\"])\n\nexport const invokeObjectMethod = (name: string, args: Array<unknown>, node: AstNode): unknown => {\n  if (!objectStatics.has(name)) throw new InterpreterRuntimeError(`Object.${name} is not available in CodeMode.`, node)\n  const requireObject = (): Record<string, unknown> => {\n    const value = boundedData(args[0], `Object.${name} input`)\n    if (isSandboxValue(value)) return {}\n    if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n      throw new InterpreterRuntimeError(`Object.${name} expects a data object.`, node)\n    }\n    return value as Record<string, unknown>\n  }\n  const guardedSet = (out: Record<string, unknown>, key: string, item: unknown): void => {\n    if (isBlockedMember(key)) throw new InterpreterRuntimeError(`Property '${key}' is not available in CodeMode.`, node)\n    out[key] = item\n  }\n  switch (name) {\n    case \"keys\": {\n      const value = boundedData(args[0], \"Object.keys input\")\n      if (isSandboxValue(value)) return []\n      if (Array.isArray(value)) return Object.keys(value)\n      if (value === null || typeof value !== \"object\") {","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/object.ts#L1-L27","documentation":"invokeObjectMethod whitelists the Object statics available in CodeMode (keys, values, entries, hasOwn, assign, fromEntries). Any other Object static, or one reached through a name not in objectStatics, throws this before any argument work happens.","triggerScenarios":"Calling Object.getOwnPropertyNames(o), Object.freeze(o), Object.entries via a typo like Object.Entries, Object.create, Object.setPrototypeOf, or Object.getPrototypeOf inside a CodeMode script.","commonSituations":"Porting utility code that mutates/freeze objects for safety; cloning logic using Object.assign misspellings or Object.getOwnPropertyDescriptors; generated code assuming full Node Object API.","solutions":["Restructure the script to use only Object.keys/values/entries/hasOwn/assign/fromEntries","Implement the needed operation manually, e.g. clone via Object.assign({}, o) instead of Object.create/defineProperties","Avoid Object.freeze entirely — the sandbox does not need mutation locking","If a static is broadly useful, add it to objectStatics and implement its case in invokeObjectMethod"],"exampleFix":"// before\nconst clone = Object.create(Object.getPrototypeOf(src)); Object.assign(clone, src)\n// after\nconst clone = Object.assign({}, src)","handlingStrategy":"validation","validationCode":"const objectStatics = new Set(['keys','values','entries','hasOwn','assign','fromEntries'])\nif (!objectStatics.has(fnName)) throw new Error(`Object.${fnName} unsupported in CodeMode`)\nif (arg === null || typeof arg !== 'object') throw new Error('Object static requires an object')","typeGuard":"const isPlainObject = (v: unknown): v is Record<string, unknown> =>\n  v !== null && typeof v === 'object' && !Array.isArray(v)","tryCatchPattern":"try {\n  return Object[fnName](target)\n} catch (e) {\n  if (e instanceof InterpreterRuntimeError && /Object\\..+ is not available/.test(e.message)) {\n    return manualObjectOperation(fnName, target)\n  }\n  throw e\n}","preventionTips":["Limit Object usage in CodeMode to the six whitelisted statics","Never freeze/create/setPrototypeOf in sandbox scripts","Review generated scripts for legacy Object APIs","Add unit tests for every Object static your scripts use"],"tags":["codemode","sandbox","object","stdlib"],"backgroundTag":"sandboxed-api-not-available","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}