(defn wrap-security
"Returns a function that wraps the given function in a sandbox.
It uses eval_soup/java.policy to define permissions. By default,
it only disallows exiting via System/exit."
[thunk]
(fn []
(System/setProperty "java.security.policy"
(-> "eval_soup/java.policy" io/resource .toString))
(System/setSecurityManager
(proxy [SecurityManager] []
(checkExit [status#]
(throw (SecurityException. "Exit not allowed.")))))
(try (thunk)
(finally (System/setSecurityManager nil)))))