Skip to content

Claude Agent SDK: spawn ENOENT when using pathToClaudeCodeExecutable in Docker container #865

@elijahbowie

Description

@elijahbowie

TL;DR

The Claude Agent SDK (@anthropic-ai/[email protected]) fails to spawn the Claude Code CLI (@anthropic-ai/[email protected]) inside a Cloudflare Container with spawn /usr/local/bin/claude ENOENT, despite the binary being installed and the pathToClaudeCodeExecutable option being explicitly set.

Related claude-code issue: anthropics/claude-code#14464

Environment

Component Value
@anthropic-ai/claude-agent-sdk 0.1.72 (installed in /opt/claude-agent-sdk/)
@anthropic-ai/claude-code 2.0.72 (global install via npm install -g)
Base Image docker.io/cloudflare/sandbox:0.6.6
Node.js v24 (from base image)
Runtime Cloudflare Containers (Durable Objects)

Error Details

Error Message:

Failed to spawn Claude Code process: spawn /usr/local/bin/claude ENOENT

Error Code: SPAWN_ERROR
Exit Code: 1
Retryable: false

Stack Trace:

Error: Failed to spawn Claude Code process: spawn /usr/local/bin/claude ENOENT
    at ChildProcess.<anonymous> (file:///opt/claude-agent-sdk/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs:13223:28)
    at ChildProcess.emit (node:events:524:28)
    at ChildProcess._handle.onexit (node:internal/child_process:293:12)

SDK Configuration Used

import { query } from '@anthropic-ai/claude-agent-sdk';

const options = {
  cwd,
  permissionMode: 'bypassPermissions',
  maxTurns: 100,
  // Explicit path to bypass PATH lookup
  pathToClaudeCodeExecutable: '/usr/local/bin/claude',
  executable: 'node',
  env: {
    PATH: '/usr/local/bin:/usr/bin:/bin',
    ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
    HOME: '/root',
    NODE_ENV: 'production',
  },
};

const response = await query({ prompt, options });

Expected Behavior

The SDK should spawn /usr/local/bin/claude successfully because:

  1. The Dockerfile runs npm install -g @anthropic-ai/[email protected] which creates /usr/local/bin/claude
  2. We explicitly pass pathToClaudeCodeExecutable: '/usr/local/bin/claude'
  3. We explicitly pass executable: 'node'
  4. We explicitly pass env.PATH including /usr/local/bin

Actual Behavior

The SDK throws ENOENT at sdk.mjs:13223 when attempting to spawn the process.

Key Observation

Pre-flight validation passes: Before calling query(), we verify the executable exists:

import { accessSync, constants } from 'fs';
accessSync('/usr/local/bin/claude', constants.X_OK); // This succeeds!

This confirms the binary exists and is executable, but the SDK still fails with ENOENT.

Dockerfile (Relevant Sections)

FROM docker.io/cloudflare/sandbox:0.6.6

# Global install creates /usr/local/bin/claude
RUN npm install -g [email protected] && \
    npm install -g @anthropic-ai/[email protected] && \
    npm cache clean --force

# Local SDK installation
ARG CLAUDE_SDK_VERSION=0.1.72
RUN mkdir -p /opt/claude-agent-sdk && \
    cd /opt/claude-agent-sdk && \
    npm init -y && \
    npm install "@anthropic-ai/claude-agent-sdk@${CLAUDE_SDK_VERSION}"

ENV PATH="/usr/local/bin:/usr/bin:/bin:/root/.local/bin:$PATH"

Questions

  1. At sdk.mjs:13223, what exact command/path is being passed to child_process.spawn()? Is it using our pathToClaudeCodeExecutable value or something else?

  2. Does the SDK spawn the Claude Code CLI directly, or does it spawn an intermediate process (e.g., npx, node, or a wrapper script)?

  3. Are there any additional environment variables or options required for Docker/container environments that aren't documented?

  4. Is there a debug mode or verbose logging option in the SDK to capture the actual spawn arguments?

  5. Does SDK version 0.1.72 have any known issues with pathToClaudeCodeExecutable being ignored?

Reproduction Steps

  1. Build container with the Dockerfile above
  2. Deploy to Cloudflare Containers (or any Docker environment)
  3. Call query() from @anthropic-ai/claude-agent-sdk
  4. Observe ENOENT error

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions