If possible, add a new variable to _G so we can check (i.e. in a local env) whether or not the script crashed sometime (f.e. to issue termination or a DebugPaue() as to avoid false prints of the last executable code every frame).
I was thinking of _G.bError = false/true set by the VScript VM. I know about pcall and xpcall but those are not an option. A way better handling would be from the sandbox.
A function wouldn't help too much I think. But your choice