Launch Python script on a Host machine within HA

Please advise how to run a Python3 script that is located outside HA directory on a Host machine?

I have a custom Python Yolo inference script that uses Nvidia CUDA (available form a host machine). Everything works pretty well, except impossibility to run this script from a shell_command within HA.
Is there a workaround for this?

If your script is outside of HA directory, you may have to whitelist the folder in Configuration>homeassistant>allowlist_external_dirs so HA can ‘see’ it.

My python scripts are inside HA folder and run fine on my Home Assistant Core using shell_command, for example:

/usr/bin/python3.10 /home/homeassistant/.homeassistant/myscripts/

Hope that helps.

I’ve tried to whitelist my folder /home/max/yolov5-flask/
and it seems that HA doesn’t allow it. I receive the error
Not a directory @ data['allowlist_external_dirs'][1]
like here

Same error in case of whitelist_external_dirs:

Here’s the excerpt:

I don’t think there is a ‘whitelist_external_dirs’ variable for homeassistant, only allowlist_external_dirs :grinning:

Yeah, but allowlist_external_dirs if I place there my /home/... directory also gives same mistake.
My script when I execute the shell_command just leaves the error in the Log:

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/
Integration: Shell Command ([documentation](, [issues](
First occurred: 20:46:21 (1 occurrences)
Last logged: 20:46:21

Error running command: `python3 /config/photos/`, return code: 1

If I read this correctly, your Home Assistant is running as a guest VM with the Host having the Yolo/CUDA-hardware python executable. If correct, you may need to have HA treat Yolo/CUDA-hardware as being on a remote machine. There are a few threads around in the HA community on how to do this using ssh. Here is one of them:

Thanks for hint, but…
I have an Error return code: 127 while executing this script:

Error running command: `sshpass -p 'pass' ssh -o StrictHostKeyChecking=no [email protected] "python3 /home/max/yolov5-flask/"`, return code: 127

I am using HA in docker, and it seems to be some kind of privileges issue specifically for my HA user. But I don’t understand what I need to do to make it fixed.

From a 3rd party PC I execute this script successfully & it does the job.


is my host machine (which concurrently runs Home Assistant docker) path.
Need help, scratching my head on finding solution.

Solved by installing ‘sshpass’ inside the Homeassistant docker container.
And now it works like a charm