Occasionally getting exit code 127's and im not sure why

So I have been running this job for a while now and on some computers I get an exit code 127, many times they start as that then will swap to a 0 others just run without issue. Any ideas of what is wrong with this script that would be causing this issue? I pulled the script out for privacy purposes but its pretty simple just pulls some data out of a database and throws it into a file for other jobs to use.

if {(name of (operating system) as string as lowercase contains "linux")} 
//Shell to Action Script Conversion Utility 
delete __appendfile 
delete /tmp/StopSaleQuery.sh
delete /tmp/StopSaleQuery.txt
 
createfile until EOF 
#!/bin/bash 
 
query="Query is redacted"
EOF

copy __createfile /tmp/StopSaleQuery.sh 
delete __appendfile 
appendfile cd /tmp 
appendfile chmod +x StopSaleQuery.sh 
appendfile ./StopSaleQuery.sh 

//modify appendfile to allow execution 
wait /bin/sh -c "chmod 555 {(client folder of current site as string) & "/__appendfile"}" 

//execute shell script as written 
wait /bin/sh -c "{(client folder of current site as string) & "/__appendfile"}" 

delete __appendfile 
delete /tmp/StopSaleQuery.sh

Don’t know if it matters but I noticed you’re not deleting __createfile before you generate it?

Consider taking a look at the path on the problem machines.

Found this on the internet

“The 127 error code indicates “command not found”. This occurs when any given command within your Bash script or on Bash command line is not found in any of the paths defined by PATH system environment variable.”

Good eye, ill add that in case it helps.