0

I'm trying to create a scripting language that compiles to Clojure, to then run it on the JVM. Each individual script, in the same JVM instance, but in an isolated manner.

Yet, when I see the implementation, I see the Clojure environment (namespaces and such) are global, so any alteration to the namespaces one script may make, affects following scripts.

I wonder if there's a way to have multiple temporary, isolated, instances of a Clojure environment in just one JVM. If not, which strategy could I use to avoid polluting global namespaces and potentially having a memory leak.

5
  • Maybe make each script compile into a separate namespace based on the script filename. Commented Apr 26, 2020 at 19:50
  • Take a look at github.com/Raynes/clojail for a library that helps running sandboxed Clojure code. Commented Apr 26, 2020 at 20:15
  • It's a library that was touched last 2013. I don't know if it can be trusted. Commented Apr 27, 2020 at 12:23
  • 1
    Does it have to be Clojure code that you generate? If you generate Java code instead, you could take a look at the Janino compiler, which can be embedded in a running JVM and compile code to classes that are loaded without restarting the JVM: janino-compiler.github.io/janino Commented Apr 28, 2020 at 12:21
  • Yep, I'm trying Groovy too. Commented Apr 28, 2020 at 13:10

1 Answer 1

0

If you want to run scripts in an isolated manner, it would be advisable to use a separate classloader for each - regardless if it is clojure or any other kind of sandboxed code.

That will allow to have multiple implementations of the same namespace (i.e. packages).

I'm not sure if the Clojure classloader will play along nicely with this though, so some experimentation is needed.

You also need to run with SecurityManager enabled and define policies that will prevent sandboxed code from accessing things like the file system, running processes, opening server sockets etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.