@anthropic-ai/claude-code SDK fails with "spawn node ENOENT" in Docker containers despite working CLI
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
- Install @anthropic-ai/claude-code@1.0.59 in a Docker container
- Install Claude CLI globally (npm install -g @anthropic-ai/claude-code)
- Use the SDK's query() function with any configuration
- 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:
- Create a Docker container with Node.js 22.14.0
- Install the Claude Code SDK
- Try to use the query() function
- 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.
11 Comments
using
spawn, I was able to get it to work only withstdio: ['ignore', 'pipe', 'pipe']ignoring the
stdinwas the trick :)I'm hitting this error outside docker container, anyone else able to fix this?
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?
Had to make sure to pass my path to env, since it failed to resolve node.
I encounter abnormal exit issues in the following scenarios, for reference:
Solution: Fix the relevant program logic
Solution: Add the
RUN apk add bashcommand to the DockerfileThe bypassPermissions mode requires sudo privileges.
Solution: Change
permissionMode: bypassPermissionstopermissionMode: defaultto resolve the issueDebugging 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
I'm encountering this same issue in a Vercel Sandbox environment. I've verified that:
PATHenvironment variable is correctly configured and passed to thequery()callHowever, the SDK continues to fail with the
spawn node ENOENTerror. I also tried hardcodingpathToClaudeCodeExecutableto 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.
@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?@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:
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:
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.
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.
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.