Skip to content

javadelight/delight-rhino-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maven Central

Rhino Sandbox

A sandbox to execute JavaScript code with Rhino in Java.

Also see Nashorn Sandbox.

Usage

By default, access to all Java classes is blocked.

RhinoSandbox sandbox = RhinoSandboxes.create();

sandbox.eval("java.lang.System.out.println('hello');");
// --> Exception

Java objects must be made explicitly available.

RhinoSandbox sandbox = RhinoSandboxes.create();

sandbox.inject("fromJava", new Object());

sandbox.eval("fromJava.getClass();");

To protect against CPU abusive scripts, limits on the number of instructions allowed for the script can be set.

RhinoSandbox sandbox = RhinoSandboxes.create();

sandbox.setInstructionLimit(1000000);

sandbox.eval("while (true) { }");
// --> results in ScriptCPUAbuseException

Versions

Contributors

Maven

Just add the following dependency to your projects.

<dependency>
    <groupId>org.javadelight</groupId>
    <artifactId>delight-rhino-sandbox</artifactId>
    <version>0.0.14</version>
</dependency>

This artifact is available on Maven Central and BinTray.

Maven Central

About

A sandbox to execute JavaScript code with Rhino in Java.

Resources

License

Stars

Watchers

Forks

Packages

No packages published