I'd like to find a way to safely run arbitrary Nimscript code. That would require finding a way to disallow unsafe actions, such as disk and network IO. Does anyone have suggestions on the best way to achieve this?
I know you could compile the code with Nim's JS backend or compile to web assembly, but i'm hoping for a solution that just works on the Nimscript interpreter without any additional runtime.
Just chop off the parts of the std lib that you consider too risky (?), you can not do much if you can not import much stuff, maybe some stuff on system still risky.
If you are on Linux theres a firejail package.
I'll also be running untrusted nimscript code in the not too distant future. I was planning to rely on os provided process sandboxing, but being able to lock down nimscript as suggested here would make my life easier. What's the general confidence level that this would actually work?
Can I lock down staticRead/staticExec? Should I assume that the code running in the nim VM can't read arbitrarily from my process's memory?
I expect I'll still use os sandboxing in my official builds, but that doesn't do anything to protect the data in my process, so protection at the vm level would be very nice.
I claim the VM's sandboxing is then very good.
That's really great to hear. Thank you very much.
Do not define the nimcore conditional symbol and then the VM does not offer staticExec/staticRead anymore.
@araq this requires recompiling nim, which shouldn't be required for the OP's request. instead, we should have:
refs: https://github.com/nim-lang/Nim/pull/16943#issuecomment-773980301 and https://forum.nim-lang.org/t/5315#48992 which discussed pretty much exactly the same topic
@araq this requires recompiling nim, which shouldn't be required for the OP's request
Er, I think he uses Nim's VM directly and the Nim compiler as a library.