Saw your previous post on Reddit. The latest version of Rhai has features to handle untrusted user-land scripts, including the abilities you were asking for.
See https://github.com/jonathandturner/rhai#ruggedization---protect-against-dos-attacks for details.