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
- Is there a way to execute a workflow JSON directly using the n8n CLI (e.g., n8n execute or similar)?
- Do I need to first import the workflow into n8n’s database, or can it be run as a standalone file?
- Is there a recommended approach using:
- n8n execute
- n8n run
- or any headless mode?
- How are credentials handled in this scenario (since UI is not being used)?
- 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 
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.
1 Like
yeah, the import + execute is solid. main headache is credentials though — since youre headless theres no UI to enter them. if youre on docker, feeding them via env vars + the --credentials flag works pretty smoothly. what kind of credentials are you dealing with?
@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. ?
the port 5679 conflict happens because the running n8n instance already claimed that port — even with N8N_RUNNERS_ENABLED=false, the CLI execution tries to start its own broker process.
two options:
option 1 — override the broker port for the exec:
sudo docker exec -it -e N8N_RUNNERS_BROKER_PORT=5680 n8n n8n execute --id=cs1aJafzGKWZrXH2
the -e flag lets you pass a different port just for that exec session.
option 2 — use the REST API instead (cleaner for automation):
curl -X POST http://localhost:5678/api/v1/workflows/cs1aJafzGKWZrXH2/run \
-H "X-N8N-API-KEY: your-api-key"
generate the API key under Settings → n8n API. this avoids port conflicts entirely and works well for scripting. credentials stay in the container’s db, no CLI conflicts.
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"
}
the python warning is a red herring — your workflow only has JS nodes so that doesnt affect execution.
the real problem with option 1 is a credential mismatch. your workflow JSON references credential id 14uuAWvu47W8hbvx (“OpenAI account”), but that id comes from the original n8n instance. in your fresh docker container, that credential simply doesnt exist — so the execution fails even though the broker started fine on port 5680.
fix: open the new n8n instance in the browser, go to Credentials → create a new OpenAI credential, then update the workflow JSON with the new credential id before importing and running it.
for option 2 — the “POST method not allowed” is expected with a Manual Trigger. that trigger type is UI-only by design and cant be invoked via REST API.
to make the curl approach work, swap the first node for a Webhook node:
- replace
manualTrigger with a Webhook node in your workflow JSON
- activate the workflow in n8n
- call the webhook URL directly — no port conflicts, no credential workarounds
thats the cleanest path for any scripted/headless execution anyway.