@anthropic-ai/claude-code SDK fails with "spawn node ENOENT" in Docker containers despite working CLI

Status Closed — not planned
Maintainer reply ✓ Yes — ashwin-ant
Activity 11 comments · opened Jul 25, 2025 · closed Feb 3, 2026
💡 Likely answer: A maintainer (ashwin-ant, collaborator) responded on this thread — see the highlighted reply below.

Claude wrote the below entirely, happy to help if I missed something

–––––––––––––––––––––––

Bug Type: SDK/Docker Integration Issue

Severity: High - Prevents SDK usage in containerized environments

Description

The @anthropic-ai/claude-code SDK consistently fails with spawn node ENOENT error when running inside
Docker containers, despite all manual spawn operations working correctly.

Environment

  • SDK Version: @anthropic-ai/claude-code@1.0.59
  • Node Version: 22.14.0
  • Platform: Docker container (linux/amd64)
  • Base Image: node:22.14.0
  • Claude CLI Version: 1.0.60

Reproduction Steps

  1. Install @anthropic-ai/claude-code@1.0.59 in a Docker container
  2. Install Claude CLI globally (npm install -g @anthropic-ai/claude-code)
  3. Use the SDK's query() function with any configuration
  4. Observe the spawn failure

Expected Behavior

The SDK should successfully spawn the Claude Code process and execute commands.

Actual Behavior

Error: Failed to spawn Claude Code process: spawn node ENOENT
at ChildProcess.<anonymous> (file:///app/node_modules/@anthropic-ai/claude-code/sdk.mjs:235:23)

Debug Evidence

✅ What Works:

  • Direct node --version: Returns v22.14.0
  • Direct claude --version: Returns 1.0.60 (Claude Code)
  • Direct node /usr/local/bin/claude --version: Returns 1.0.60 (Claude Code)
  • Manual spawn with exact SDK command: Works perfectly

❌ What Fails:

  • SDK query() function: Always fails with spawn node ENOENT

PATH Information

PATH=/usr/local/bin:/usr/bin:/bin:/app/node_modules/.bin:...
Available node executables: /usr/local/bin/node, /usr/bin/node, /bin/node

Code Example

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

// This fails with spawn node ENOENT
for await (const message of query({
prompt: "test",
options: {
permissionMode: 'bypassPermissions',
pathToClaudeCodeExecutable: '/usr/local/bin/claude'
}
})) {
// Never reached
}

Workaround

Direct CLI invocation works:
const claudeProcess = spawn('node', ['/usr/local/bin/claude', '--version']);
// This works perfectly

Root Cause Analysis

The SDK's internal spawn mechanism in sdk.mjs:235 appears to have environment inheritance issues in
Docker containers, despite the same spawn command working when called manually.

To reproduce this issue:

  1. Create a Docker container with Node.js 22.14.0
  2. Install the Claude Code SDK
  3. Try to use the query() function
  4. Observe the consistent failure

This bug makes the SDK unusable in Docker/containerized environments, which is a significant limitation
for CI/CD and deployment scenarios.

View original on GitHub ↗

11 Comments

jbrower95 · 1 year ago

using spawn, I was able to get it to work only with stdio: ['ignore', 'pipe', 'pipe']

ignoring the stdin was the trick :)

tabletenniser · 1 year ago

I'm hitting this error outside docker container, anyone else able to fix this?

frmsaul · 11 months ago

If this sdk doesn't work inside of a container, i struggle to understand what it's even for?
Does anyone use it in production?

Pagebakers · 10 months ago

Had to make sure to pass my path to env, since it failed to resolve node.

    const agentQuery = query({
      prompt: task,
      options: {
        model: 'claude-sonnet-4-5-20250929',
        maxTurns: 20,
        cwd: process.cwd(),
        env: {
          PATH: process.env.PATH,
          ANTHROPIC_API_KEY,
        },
      },
    });
renxia · 9 months ago

I encounter abnormal exit issues in the following scenarios, for reference:

  1. The specified path for cwd does not exist

Solution: Fix the relevant program logic

  1. Under the Docker Alpine image, Bash is specified in allowedTools
query({
   allowedTools: [
      Bash,
      BashOutput,
      KillBash
   ],
})

Solution: Add the RUN apk add bash command to the Dockerfile

  1. The bypassPermissions setting is configured in Docker

The bypassPermissions mode requires sudo privileges.

Solution: Change permissionMode: bypassPermissions to permissionMode: default to resolve the issue

Debugging Tips: By setting the DEBUG=* environment variable, you can view the runtime logs of Claude Code, which helps you better understand the causes of abnormal exits.

from https://lzw.me/a/claude-agent-sdk-exited-with-code-1.html

josh-d2 · 9 months ago

I'm encountering this same issue in a Vercel Sandbox environment. I've verified that:

  • The Claude Code CLI is properly installed in the container
  • The PATH environment variable is correctly configured and passed to the query() call
  • The CLI works when invoked directly from the command line

However, the SDK continues to fail with the spawn node ENOENT error. I also tried hardcoding pathToClaudeCodeExecutable to the Claude Code CLI path in my container to no avail.

@ashwin-ant, could you provide an update on the status of this issue? Since this was reported in July, I wanted to check if there's a fix planned or if there's a recommended workaround in the meantime. This limitation is currently blocking our ability to integrate the SDK into containerized/production environments, so any guidance would be greatly appreciated.

If there are any additional diagnostic steps or configurations I should try, I'm happy to help test potential solutions.

ashwin-ant collaborator · 9 months ago

@josh-d2 can you share more about your setup? That is, what sort of options are you passing into query? Are you running as root or using any specific permission mode?

josh-d2 · 9 months ago

@ashwin-ant, I discovered this issue while following this Vercel tutorial for running Claude's tooling in a Vercel Sandbox.

Key difference that triggers the bug:

  1. The tutorial directly invokes the Claude Code CLI (@anthropic-ai/claude-code) and works fine
  2. My application uses the Claude Agent SDK (@anthropic-ai/claude-agent-sdk) as a dependency, which then invokes Claude Code internally
  3. My app works locally but fails with the spawn node ENOENT error in the sandbox environment

This suggests the issue is specifically with how the Agent SDK spawns the Claude Code process in containerized environments, rather than with the Claude Code CLI itself.

Interesting note: The Vercel tutorial is titled "Using Vercel Sandbox to run Claude's Agent SDK" but actually demonstrates using the Claude Code CLI directly, not the Agent SDK. I wonder if the tutorial author originally attempted to use the Agent SDK, encountered this same spawn issue, and pivoted to using the CLI directly—but forgot to update the tutorial title.

This would explain why:

  1. The tutorial works (it's using the CLI directly)
  2. My implementation fails (it's using the Agent SDK, which has the spawn bug)
  3. The title is misleading (it claims to show Agent SDK usage)
github-actions[bot] · 7 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] · 6 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] · 6 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.