That was a very good, detailed first post!
Thanks @scottgus1 !
Unfortunately, it's exactly the same solution for exactly the same problem.
I thought you might say that.
Stop using a Virtualbox Shared Folder for execution of scripts, for all the reasons stated above. Use a real shared folder, shared from the host OS over a network.
It looks like we may indeed have to. It's a great shame if that's the case. In my experience, many developers rely on the bi-directional file-syncing for efficient developer workflows between host and guest. Of course other options (docker, kvm, cloud instance, ...) are available, but VirtualBox remains a useful tool to have at our disposal, especially where a full OS instance is required. It's convenient, fast, simple to orchestrate, and reliable.
I do find it odd that VSF's were designed only for manual copying of files, and yet it has worked for all of these many years. I had a quick scan of the documentation (chapter 4; I am not permitted to post URLs on my first day on the forum) and can find no mention of this limitation in the design. Not can I find any mention of this on the forum up until now. For example, the "HOWTO: Use Shared Folders" at /viewtopic.php?f=3&t=15868 does not mention it.
I find it doubly odd that a virtual filesystem which otherwise feels POSIX-ish with execute bits and so on can influence the efficacy of the shebang. But there we are.
I do wonder if the "bug" (if I may be so bold) is within VirtualBox, or has been introduced elsewhere. As I noted in my post earlier, it still works on an Ubuntu 18.04 guest for me.
(When one posts on an existing topic one is expected to have read the topic and tried the suggested solutions.. It appears you may not have done this, otherwise you'd know that Virtualbox Shared Folders was not designed for your chosen process.)
I have used other methods such as network (nfs) sharing in the past, and they have served me well. But given that VSFs have worked so well up until now, there has been little incentive to go to such extravagant lengths. I read the topic thoroughly before responding, and added my own experiences to the discussion in the spirit of co-operation. Thus I regard your criticism as unwarranted. As you have doubtless contributed more to my prosperity via your contributions to the venerable VirtualBox, than I have to yours, I will simply wish you well, and move on.
edit: I did subsequently find a mention from your good self of this at /viewtopic.php?f=6&t=80854