{"id":25845934,"url":"https://github.com/archiecobbs/javabox","last_synced_at":"2026-06-12T05:31:53.053Z","repository":{"id":279817905,"uuid":"940077604","full_name":"archiecobbs/javabox","owner":"archiecobbs","description":"Scripting in Java, by Java, for Java","archived":false,"fork":false,"pushed_at":"2025-07-27T23:33:55.000Z","size":5330,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-24T21:48:36.441Z","etag":null,"topics":["java","jshell","sandbox","scripting"],"latest_commit_sha":null,"homepage":"https://archiecobbs.github.io/javabox/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archiecobbs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-27T15:22:50.000Z","updated_at":"2026-01-22T16:04:51.000Z","dependencies_parsed_at":"2025-02-27T22:15:04.430Z","dependency_job_id":"f2420b99-e47d-48cd-813d-23b576af1ed3","html_url":"https://github.com/archiecobbs/javabox","commit_stats":null,"previous_names":["archiecobbs/javabox"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/archiecobbs/javabox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archiecobbs%2Fjavabox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archiecobbs%2Fjavabox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archiecobbs%2Fjavabox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archiecobbs%2Fjavabox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archiecobbs","download_url":"https://codeload.github.com/archiecobbs/javabox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archiecobbs%2Fjavabox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34231214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jshell","sandbox","scripting"],"created_at":"2025-03-01T08:33:08.060Z","updated_at":"2026-06-12T05:31:53.049Z","avatar_url":"https://github.com/archiecobbs.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaBox\n_Scripting in Java, by Java, for Java_\n\n### What is it?\n\nJavaBox tries to answer the question, \"Where is the thing that will let me run scripts written in Java within my Java application?\"\n\nJavaBox is a simple container (\"sandbox\") for executing scripts written in Java. JavaBox does **not** provide a secure sandbox; it's not safe for untrusted code.\n\nInstead, it provides a basic sandbox that allows you to impose simple controls like time limits, instruction count limits, and restrictions on accessible classes. This allows, for example, an application to use Java as a runtime configuration language while having the ability to restrict unwanted functionality like network I/O, `System.exit()`, etc.\n\n### How does it Work?\n\nEach JavaBox instance relies on an underlying [JShell](https://docs.oracle.com/en/java/javase/24/jshell/introduction-jshell.html) instance configured for local execution mode. That means JavaBox scripts are really JShell scripts that happen to be executing on the same JVM instance. Unlike normal JShell scripts, which can only return strings, JavaBox scripts can return arbitrary Java objects, and those objects can then be used outside of the scripting environment.\n\nJavaBox supports imposing restrictions on scripts using [Controls](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/Control.html). Controls are allowed to [intercept](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/Control.html#modifyBytecode(java.lang.constant.ClassDesc,byte%5B%5D)) a script's class loading step and [each time](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/Control.html#startExecution(org.dellroad.javabox.Control.ContainerContext)) it executes.\n\nJavaBox supports [interrupting](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/JavaBox.html#interrupt()) scripts in the middle of execution if necessary, and it also has [suspend](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/JavaBox.html#suspend(java.lang.Object)) and [resume](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/JavaBox.html#resume(java.lang.Object)) functions, allowing an application thread to suspend scripts on certain operations and regain control.\n\n### Examples\n\nHere's a \"Hello, World\" example:\n```java\nObject returnValue;\ntry (JavaBox box = new JavaBox(Config.builder().build())) {\n    box.initialize();\n    box.setVariable(\"target\", \"World\");\n    String script = \"String.format(\\\"Hello, %s!\\\", target);\";\n    returnValue = box.execute(script).returnValue();\n}\nSystem.out.println(returnValue);     // prints \"Hello, World!\"\n```\n\nHere's an example that shows how to use a [`TimeLimitControl`](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/control/TimeLimitControl.html) to kill a script that takes too long:\n```java\n// Set up control\nConfig config = Config.builder()\n  .withControl(new TimeLimitControl(Duration.ofSeconds(5)))\n  .build();\n\n// Execute script\nScriptResult result;\ntry (JavaBox box = new JavaBox(config)) {\n    box.initialize();\n    result = box.execute(\"\"\"\n        while (true) {\n            Thread.yield();\n        }\n    \"\"\");\n}\n\n// Check result\nswitch (result.snippetOutcomes().get(0)) {\ncase SnippetOutcome.ExceptionThrown e when e.exception() instanceof TimeLimitExceededException\n  -\u003e System.out.println(\"script was taking too long\");\n}\n```\n\n### Caveats\n\n* The `controls` module requires Java 24+ because it uses the new `ClassFile` API; everything else requires JDK 17+.\n\n### Where do I get it?\n\nJavaBox is available from [Maven Central](https://central.sonatype.com/search?q=g%3Aorg.dellroad+javabox).\n\n### More Information\n\n  * [API Javadocs](https://archiecobbs.github.io/javabox/site/apidocs/org/dellroad/javabox/JavaBox.html)\n  * [Maven Site](https://archiecobbs.github.io/javabox/site/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchiecobbs%2Fjavabox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchiecobbs%2Fjavabox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchiecobbs%2Fjavabox/lists"}