0

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.

flypig
  • 43
  • 6

1 Answers1

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/

[2] How should I load Jars dynamically at runtime?

Christian Humer
  • 471
  • 3
  • 6