graal can sandbox js, ruby and other languages when create context, but how to sandbox a dynamic loaded jar? For example, how to sandbox a custom uploaded jar when used in flink as udf.
Asked
Active
Viewed 731 times
1 Answers
1
Java bytecodes can currently not be sandboxed using the polygot API [1]. Like with any other JDK you can sandbox a jar by creating a new classloader [2].
URLClassLoader child = new URLClassLoader(myJar.toURL(),
this.getClass().getClassLoader());
Class classToLoad = Class.forName("com.MyClass", true, child);
Method method = classToLoad.getDeclaredMethod("myMethod");
Object instance = classToLoad.newInstance();
Object result = method.invoke(instance);
[1] http://www.graalvm.org/docs/graalvm-as-a-platform/embed/

Christian Humer
- 471
- 3
- 6
-
Is it possible that implement a guest language jvm bytecode interpreter to support sandbox using the polyglot API? – flypig Jul 13 '18 at 02:31
-
Yes. That is a possibility. And we are working on such an interpreter atm. – Christian Humer Aug 09 '18 at 21:43