Shell Command process launched from HA gets automatically killed

I’m using a Shell Command to run Python image inference and it should be working in accordance to a particular sensor state. If sensor is ON, my shell command gets launched:

shell_command:
  camdetect_start: sshpass -p 'pass' ssh -tt [email protected] 'echo pass| sudo -S -s /bin/bash -c "python3 /home/max/camdetect.py"'

In case sensor is OFF, then this process gets killed by another shell command:
sshpass -p 'pass' ssh -tt [email protected] 'echo pass| sudo -S -s /bin/bash -c "pkill -9 -f camdetect.py"

When I launch the 1st command, the Python process works for some time and then suddenly gets killed. It’s strange because if I launch the same bash command from within Ubuntu terminal, it stays in memory unless I manually kill it. Why does it happen like that?
Is there any special way of launching shell script I need to use from HA?
Same thing happens when I launch the command from Node Red.

Are you possibly running up against ssh timeouts?

https://linuxhint.com/increase-ssh-connection-timeout/

I don’t know if your guess might be a solution, but if I launch the same Python process thru SSH via Putty, it lives until I terminate it. It gets terminated when launched from HA quite fast though.
Server SSH parameters are untouched at the same time.