I am creating something that will take arbitrary Groovy code and execute it (IRC bot). I know how to access files in a sandbox, threads, etc. Using SecurityManagers, but I want the script to be killed if it uses 128 MB of RAM or 3 seconds of runtime (so no one runs it while (true){})., Here is my code:
private static Object eval(String code) {
GroovyShell sh = new GroovyShell()
return sh.parse(code).run()
}
I really do not want to create a new JVM, because I would like to have exceptions thrown to the main program and the actual objects passed instead of strings (for reuse if I ever intend to make other interface modules).
source
share