n8n Execute Command Node Invalid Command Error

Step by Step Guide to solve n8n Execute Command Node Invalid Command Error

 


 

Who this is for: n8n developers and automation engineers who use the Execute Command node in self‑hosted or Docker deployments and need to resolve “Invalid command”, “command not found”, or “permission denied” errors. We cover this in detail in the n8n Node Specific Errors Guide.

 


Quick Diagnosis

Symptom Typical cause Quick fix
command not found Wrong or missing PATH, relative path, or typo Use an absolute path (/usr/bin/ffmpeg) or add the directory to PATH in the node’s “Environment Variables”.
permission denied Binary isn’t executable for the n8n user (often node in Docker) chmod +x /path/to/binary or run as root (USER root in Dockerfile).
sh: 1: …: not found (Linux) Non‑interactive shell can’t locate the command Prefix with bash -c or set Shell to /bin/bash in node options.
error: spawn … ENOENT (Windows) Wrong extension or missing .exe Append .exe (e.g., ffmpeg.exe) or use the full Windows path (C:\\Program Files\\ffmpeg\\ffmpeg.exe).

One‑line fix: Set the Command field to the absolute binary path and, if needed, add chmod +x or adjust Environment → PATH so the binary is reachable.


1. Why the Execute Command node says “Invalid command”

If you encounter any n8n code node runtime error resolve them before continuing with the setup.

The node spawns a child process via Node.js child_process.spawn. It inherits the runtime’s environment, working directory, and user. If the binary can’t be resolved in that context, the OS returns *command not found* or *permission denied*, which n8n surfaces as “Invalid command”.

Key concepts that matter

Concept What n8n inherits Why it matters
PATH variable From the container/host environment Determines whether a bare command (ffmpeg) can be located.
Working directory process.cwd() of the n8n process Relative paths (./script.sh) resolve against this folder.
User UID/GID Usually node (UID 1000) in Docker, or the OS user running n8n Controls file‑system permissions.
Shell /bin/sh on Linux, cmd.exe on Windows (unless overridden) Affects built‑in commands (&&, pipes).

2. Step‑by‑step diagnosis checklist

If you encounter any n8n if node conditional evaluation error resolve them before continuing with the setup.

Follow the checklist in order; tick each item as you verify it.

Steps Action How to test
1 Confirm the exact error string Open the node → “Execution” tab → copy the red message.
2 Run the same command locally (outside n8n) on the same host/container docker exec -it <n8n_container> /bin/bash -c "ffmpeg -version"
3 Check the binary’s absolute path which ffmpeg (Linux) or where ffmpeg.exe (Windows)
4 Verify execute permission for the binary ls -l $(which ffmpeg) – look for the x flag
5 Inspect the node’s Environment Variables → ensure PATH includes the binary’s directory Add a **Set** node before the Execute Command node that outputs $PATH.
6 Set “Shell” to /bin/bash (Linux) or cmd.exe /C (Windows) if you need shell features Node → “Advanced” → “Shell”.
7 Use an absolute path in the “Command” field Replace ffmpeg with /usr/bin/ffmpeg.
8 If using Docker, ensure the binary is installed in the image or mounted via a volume Check Dockerfile or docker run -v /host/bin:/usr/bin.
9 Re‑run the workflow and verify the node succeeds Click “Execute Workflow”.
10 Log full stdout/stderr for future debugging Enable “Continue on Fail” → add a **Set** node to capture $node["Execute Command"].error.

3. Common root causes & precise fixes

3.1 Command‑not‑found (PATH issue)

Symptoms: sh: 1: ffmpeg: not found or command not found.

Fix 1 – Use an absolute path

Command: /usr/bin/ffmpeg

Fix 2 – Extend PATH in the node

{
  "name": "PATH",
  "value": "/usr/local/bin:/usr/bin:/bin:/opt/ffmpeg"
}

Fix 3 – Docker‑specific mount

docker run -d \
  -v /usr/bin/ffmpeg:/usr/bin/ffmpeg \
  -e PATH="/usr/bin:$PATH" \
  n8nio/n8n

3.2 Permission denied (exec rights)

Symptoms: permission denied, spawn … ENOENT.

Situation Remedy
Binary owned by root, n8n runs as node (UID 1000) chmod o+x /usr/bin/ffmpeg or chown node:node /usr/bin/ffmpeg.
Script without shebang (#!/bin/bash) Add the shebang line and chmod +x script.sh.
Read‑only container Re‑build the image with the binary in a writable layer or mount a writable volume.
Need sudo (rare) Prefer running the container as root (USER root in Dockerfile) or grant capabilities (setcap).

3.3 Shell vs. direct exec mismatch

Symptoms: sh: 1: syntax error … or error: spawn … ENOENT when using &&, pipes, etc.

Fix – Wrap with a shell

bash -c "ffmpeg -i input.mp4 -c:v libx264 output.mp4 && echo done"

Alternative – Set the node’s Shell option

Shell: /bin/bash   (Linux)
Shell: cmd.exe /C  (Windows)

3.4 Windows‑specific quirks

Issue Cause Fix
ffmpeg is not recognized … PATH missing FFmpeg folder Add C:\\Program Files\\ffmpeg\\bin to the node’s PATH.
error: spawn C:\ffmpeg.exe ENOENT Backslashes not escaped in JSON Use double backslashes C:\\ffmpeg.exe or wrap the command in quotes.
Access is denied Binary not executable for the service account Run n8n as Administrator or grant read/execute rights to Everyone.

4. Full example – Running FFmpeg in an Execute Command node

If you encounter any n8n error node catch all failure resolve them before continuing.

4.1 Minimal node configuration (JSON export)

{
  "name": "Execute FFmpeg",
  "type": "n8n-nodes-base.executeCommand",
  "position": [400, 300],
  "parameters": {
    "command": "/usr/bin/ffmpeg",
    "options": "-i /data/input.mp4 -c:v libx264 /data/output.mp4",
    "workingDirectory": "/data",
    "shell": "/bin/bash"
  }
}

Add the PATH environment variable separately:

{
  "name": "PATH",
  "value": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/ffmpeg"
}

4.2 Dockerfile snippet (install FFmpeg)

FROM n8nio/n8n:latest

# Install ffmpeg (Alpine)
RUN apk add --no-cache ffmpeg

# Ensure the n8n user can execute it
RUN chmod +x /usr/bin/ffmpeg

VOLUME ["/data"]

4.3 Testing the node locally (CLI)

docker exec -it n8n_container /bin/bash -c "/usr/bin/ffmpeg -version"
# Should print version info – if not, revisit the checklist.

5. EEFA (Experience, Errors, Fixes, Advice) notes

  • Security warning – Never pass unchecked user input directly into the Execute Command node. Sanitize or whitelist allowed commands to avoid command injection.
  • Production tip – Keep “Continue On Fail” disabled; let the workflow stop on a bad command so you can catch the error early.
  • Performance tip – For many short commands, reuse a long‑running shell via the **Run Script** node instead of spawning a new process each time.
  • Cross‑platform tip – Store the binary path in an environment variable (FFMPEG_PATH) and reference it as {{$env.FFMPEG_PATH}}. This makes the workflow portable between Linux and Windows hosts.

7. Next steps

  • n8n Execute Command node “exit code != 0” – handling non‑zero exit statuses.
  • n8n Execute Command node “timeout” – preventing hanging processes.
  • n8n Execute Command node “output parsing” – extracting JSON or CSV from command output.

Conclusion

The “Invalid command” error in the Execute Command node is almost always a PATH, permission, or shell mismatch problem. By confirming the exact error, testing the command directly, ensuring the binary’s absolute path and execute rights, and configuring the node’s environment (PATH, Shell, Docker volume), you can turn a vague failure into a reliable, production‑ready workflow. Apply the checklist, use the minimal code examples, and keep security and performance best practices in mind to keep your n8n automations robust.


Leave a Comment

Your email address will not be published. Required fields are marked *