Earlier quoted context omitted.
I’m guessing something like `chown root ~/.bash*` would prevent that, if all the folders in your PATH are owned by root.
You can close some gaps, but at the end of the day you can't expect that you'll run malicious code but it won't do this or that. For example the X server allows any client to listen for key events or hook into other windows.
That's one of the reasons why "lock screens" are a lie under X.
But that's one of the problems Wayland solves. It has a much better security story.