This tool executes arbitrary code without sandboxing. For prototyping only!
-
List available examples:
bazel run //:cli -- list
-
Run a simple example:
bazel run //:cli -- example simple
-
Try the Guava example:
bazel run //:cli -- example guava
-
Create a simple Java file (
MyCode.java):import java.util.function.BiFunction; public class MyCode implements BiFunction<String, String, String> { @Override public String apply(String key, String data) { return key + " processed: " + data; } }
-
Run it:
bazel run //:cli -- file /path/to/MyCode.java mykey "test data"
import com.example.coderunner.CodeRunner;
public class Example {
public static void main(String[] args) throws Exception {
CodeRunner<String, String, String> runner = new CodeRunner<>();
String code = """
import java.util.function.BiFunction;
public class MyFunction implements BiFunction<String, String, String> {
public String apply(String key, String data) {
return key + ": " + data.toUpperCase();
}
}
""";
String result = runner.runCode("test", "hello world", code);
System.out.println(result); // Prints: test: HELLO WORLD
}
}All examples are in the examples/ directory. Run them using absolute paths:
# Word counter
bazel run //:cli -- file $PWD/examples/WordCounter.java doc "hello world test"
# Calculator
bazel run //:cli -- file $PWD/examples/Calculator.java add "10,20"
# List processor (uses Guava)
bazel run //:cli -- file $PWD/examples/ListProcessor.java items "a,b,c,d"Your code can use:
- ✅ Java standard library
- ✅ Guava library
- ✅ Collections and Streams
- ✅ Any Java language features
⚠️ BUT: No sandboxing! Full system access!
- Read the full README for details
- Check the examples directory for more samples
- Review CodeRunner.java for API details