Running n8n Workflow JSON via CLI (No UI) on Ubuntu

Hi everyone,

I’m looking for guidance on executing an existing n8n workflow purely via CLI, without using the n8n UI at all.

Context

  • I have a workflow.json
  • The workflow is already fully defined (nodes, connections, etc.)
  • I want to run this workflow locally on Ubuntu
  • I do NOT want to run via n8n editor UI

Goal
I’m trying to achieve something like:

  • Load workflow JSON
  • Execute it directly from terminal / CLI
  • Pass the credentials via CLI
  • Get logs/output in the terminal

Example

  • Execute a simple workflow that interacts with a GPT model
  • Capture and print the generated text output

Questions

  1. Is there a way to execute a workflow JSON directly using the n8n CLI (e.g., n8n execute or similar)?
  2. Do I need to first import the workflow into n8n’s database, or can it be run as a standalone file?
  3. Is there a recommended approach using:
    • n8n execute
    • n8n run
    • or any headless mode?
  4. How are credentials handled in this scenario (since UI is not being used)?
  5. Any best practices for running workflows in a fully headless / automation-friendly setup?

What I Tried

  • I tried running n8n via Docker, but I’m running into a port issue on 5679 (port conflict / binding error)
    • n8n Task Broker’s port 5679 is already in use. Do you have another instance of n8n running already?

If anyone has experience running n8n workflows in a fully CLI-driven or headless environment, I’d really appreciate your guidance :folded_hands:
Thanks in advance!

Hi @Stephanc Welcome!
First i would recommend reading this:

and now for doing that kind of direct execution from CLI, i think first you need to import your flow via:
n8n import:workflow --input=workflow.json
and then once you have got the ID for that, you can execute it using that ID:
n8n execute --id <ID>
and for your port conflict i think you should try:
N8N_RUNNERS_ENABLED=false or also if you want you can just flip and change the port with N8N_RUNNERS_BROKER_PORT.

for credentials i would say they must be pre imported ofc else how you would be able to use that and you cannot pass them via CLI flags or command kind of.

@Anshul_Namdev @Benjamin_Behrens

I tried running n8n with N8N_RUNNERS_ENABLED=false. Below is the Docker command I used:

sudo docker run -d \
 --name n8n \
 --restart unless-stopped \
 -p 5678:5678 \
 -e GENERIC_TIMEZONE="Europe/Warsaw" \
 -e TZ="Europe/Warsaw" \
 -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
 -e N8N_RUNNERS_ENABLED=false \
 -v n8n_data:/home/node/.n8n \
 docker.n8n.io/n8nio/n8n

Here is the workflow JSON that I want to execute via CLI:

sudo docker exec -it n8n n8n export:workflow --all | jq '.[] | {id, name}'

{
  "id": "cs1aJafzGKWZrXH2",
  "name": "openai"
}
sudo docker exec -it n8n n8n execute --id=cs1aJafzGKWZrXH2
n8n Task Broker's port 5679 is already in use. Do you have another instance of n8n running already?

can u help me with the solution. ?

thank you.

I tried with both the options that you gave
for the option 1, i got error

n8n Task Broker ready on 127.0.0.1, port 5680
Failed to start Python task runner in internal mode. because Python 3 is missing from this system. Launching a Python runner in internal mode is intended only for debugging and is not recommended for production. Users are encouraged to deploy in external mode. See: https://docs.n8n.io/hosting/configuration/task-runners/#setting-up-external-mode
Execution was NOT successful. See log message for details.
Execution error:
====================================

and for the Option 2 , after generating the API key and running the curl, it says

{
    "message": "POST method not allowed"
}