danny-avila/LibreChat · error

Code execution is not enabled for Agents

Error message

Code execution is not enabled for Agents

What it means

Thrown when `tool_resource === EToolResources.execute_code` but `checkCapability(req, AgentCapabilities.execute_code)` returns false. The capability flag is set per-agent (or per-tenant) admin config; without it the code execution tool is not authorized for this agent, so its dedicated upload path (codeapi session file) is blocked before any I/O.

Source

Thrown at api/server/services/Files/process.js:696

    throw new Error('No tool resource provided for agent file upload');
  }

  if (tool_resource === EToolResources.file_search && file.mimetype.startsWith('image')) {
    throw new Error('Image uploads are not supported for file search tool resources');
  }

  if (!messageAttachment && !agent_id) {
    throw new Error('No agent ID provided for agent file upload');
  }

  const isImage = file.mimetype.startsWith('image');
  let fileInfoMetadata;
  const entity_id = messageAttachment === true ? undefined : agent_id;
  const basePath = mime.getType(file.originalname)?.startsWith('image') ? 'images' : 'uploads';
  if (tool_resource === EToolResources.execute_code) {
    const isCodeEnabled = await checkCapability(req, AgentCapabilities.execute_code);
    if (!isCodeEnabled) {
      throw new Error('Code execution is not enabled for Agents');
    }
    const { handleFileUpload: uploadCodeEnvFile } = getStrategyFunctions(FileSources.execute_code);
    const stream = fs.createReadStream(file.path);
    /* Resource identity for codeapi's sessionKey:
     * - chat attachments (messageAttachment=true): `kind: 'user'`, codeapi
     *   buckets under `<tenant>:user:<authContext.userId>` regardless of `id`.
     * - agent setup files (messageAttachment=false): `kind: 'agent'`, shared
     *   per agent identity. `id` carries the agent id. */
    const codeKind = messageAttachment === true ? 'user' : 'agent';
    const codeId = messageAttachment === true ? req.user.id : agent_id;
    /* Upload under the same sanitized filename LC stores in its DB
     * (`fileInfo.filename` below uses `sanitizeFilename(originalname)`).
     * Codeapi/file_server use this as the on-disk name in the sandbox
     * — `/mnt/data/<filename>` — and `primeFiles`'s `toolContext` text
     * + `_injected_files.name` both reference `file.filename`. Sending
     * the unsanitized `file.originalname` here makes the sandbox path
     * (with spaces / special chars) drift from what LC tells the model
     * is available, causing FileNotFoundError on the first reference. */

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Enable the execute_code capability for the agent (admin settings / agent config).
  2. If code execution should stay off, remove `execute_code` from the agent's tool_resources and stop uploading to it.
  3. Frontend: hide/disable the execute_code upload UI when the capability is not enabled.
  4. Check the tenant/role capability matrix if multi-tenant — the user's tenant may not have the feature.
Defensive patterns

Strategy: validation

Validate before calling

async function assertExecuteCodeEnabled(req) {
  const ok = await checkCapability(req, AgentCapabilities.execute_code);
  if (!ok) throw new Error('Enable execute_code capability for this agent');
}

Try / catch

try { await processAgentFileUpload(params); }
catch (e) {
  if (/Code execution is not enabled/.test(e.message)) return res.status(403).json({ error: e.message });
  throw e;
}

Prevention

When it happens

Trigger: An upload to an agent with `tool_resource: execute_code` where the agent (or its model/tenant) does not have the execute_code capability enabled. Also when a user tries to use a tool resource the admin has globally disabled.

Common situations: Admin disabled code execution globally but a stale agent still references the tool resource; user copying an agent config across environments where the capability is off; a new install where execute_code requires explicit opt-in.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/85576034bc938b6b. Report an issue: GitHub.