# N8n running python script

**URL:** <https://community.n8n.io/t/n8n-running-python-script/262351>\
**Category:** Questions\
**Created:** [February 8, 2026, 1:53pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351 "2026-02-08T13:53:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader95](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/nader95/32/135001_2.png) [@nader95](https://community.n8n.io/u/nader95)\
**Post date:** [February 8, 2026, 1:53pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/1 "2026-02-08T13:53:00Z")

</div>

Hey Jan, how are you? hope you are doing well

I saw your contribution in some posts here in the n8n community and I will be really appreciated if you can help me with an n8n python scripts running case.

I have a n8n hosted on VPS with Coolify panel and I want it to run at some point in the workflow to run a Python script hosted also on the same VPS. I have created a Python worker container on Coolify so I can make it control all Python work (picture 1)

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/a/e/ae9e90af5c861acf2ea6ff56bfd46108320e4f51.jpeg)

This python-worker container was created on Coolify using a Github repository has a dockerfile (picture 2)

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/4/4/442bae5e584f6a0eb3adf965c79e26ac4f8630aa.png)

when I tried to run the container from inside n8n workflow with the execute command node (picture 3)

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/d/7/d766439b30622e4aa26e14bcf590fcf4555211cb.png)

I got the error you see “/bin/sh: docker not found”

Am I trying to run the scripts in a right way? and where is the issue here

---

<div class="post-metadata">

**Author:** ![nader95](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/nader95/32/135001_2.png) [@nader95](https://community.n8n.io/u/nader95)\
**Post date:** [February 8, 2026, 1:55pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/2 "2026-02-08T13:55:41Z")

</div>

@jan Have a look please @A_A4

---

<div class="post-metadata">

**Author:** ![A\_A4](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/a_a4/32/58794_2.png) [@A\_A4](https://community.n8n.io/u/A_A4)\
**Post date:** [February 8, 2026, 2:00pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/3 "2026-02-08T14:00:33Z")

</div>

Hi @nader95

**Most likely:** You are trying to run the `docker` command from _inside_ the n8n container, but the n8n image does not have the Docker CLI installed or access to the host’s Docker socket.

**Try:**  
• **Add** an **SSH** node to your workflow instead of the “Execute Command” node.  
• **Connect** the SSH node to your VPS host IP using your server credentials.  
• **Execute** the command `docker exec python-worker python /data/scripts/test.py` via the SSH node.  
• **Ensure** the SSH user has permission to run Docker (add the user to the `docker` group).

hope this help!

---

<div class="post-metadata">

**Author:** ![nader95](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/nader95/32/135001_2.png) [@nader95](https://community.n8n.io/u/nader95)\
**Post date:** [February 8, 2026, 2:09pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/4 "2026-02-08T14:09:36Z")

</div>

First of all thanks for your time and help I really appreciate it. Let me try that method.

Is it the best solution to run a Python script as compatibility and for future updates? as I saw many recommendation for using FastAPI and n8n task runners, but I don’t have any experience with these two.

---

<div class="post-metadata">

**Author:** ![A\_A4](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/a_a4/32/58794_2.png) [@A\_A4](https://community.n8n.io/u/A_A4)\
**Post date:** [February 8, 2026, 2:17pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/5 "2026-02-08T14:17:22Z")

</div>

What i know is wrapping your script in a simple API (using **FastAPI** ) is the superior, future-proof solution compared to SSH.because when using **SSH** , if you change your server password or keys, the automation breaks. It also grants n8n “root” access, which is a security risk.

---

<div class="post-metadata">

**Author:** ![nader95](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/nader95/32/135001_2.png) [@nader95](https://community.n8n.io/u/nader95)\
**Post date:** [February 8, 2026, 2:21pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/6 "2026-02-08T14:21:52Z")

</div>

Aha Great got it, final request, if you have any guides for this **FastAPI** part to and how to develop it, I will be very grateful.

---

<div class="post-metadata">

**Author:** ![A\_A4](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/a_a4/32/58794_2.png) [@A\_A4](https://community.n8n.io/u/A_A4)\
**Post date:** [February 8, 2026, 2:34pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/7 "2026-02-08T14:34:16Z")

</div>

```python
from fastapi import FastAPI
import subprocess

app = FastAPI()

@app.post("/run-script")
async def run_script():
    # Runs your existing script
    result = subprocess.run(["python", "/data/scripts/test.py"], capture_output=True, text=True)
    return {"output": result.stdout, "error": result.stderr}

```

**try theses steps:**  
• **Update** your `requirements.txt` to include `fastapi` and `uvicorn`.  
• **Add** a simple `main.py` to your repository (see guide below) to accept a POST request and run your logic.  
• **Change** the `CMD` in your Dockerfile to: `CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]`.  
• **Replace** the SSH node in n8n with an **HTTP Request** node pointing to `http://<container-name>:3000/run-script`.

hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [February 15, 2026, 2:35pm UTC](https://community.n8n.io/t/n8n-running-python-script/262351/8 "2026-02-15T14:35:11Z")

</div>

Closed on February 15, 2026, 2:35pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
