Created
December 13, 2010 19:31
-
-
Save anonymous/739467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<gtrak> (find-doc "alter-var-root") | |
<sexpbot> ⟹ ------------------------- clojure.core/alter-var-root ([v | |
f & args]) Atomically alters the root binding of var v by applying f | |
to its current value plus any args ------------------------- | |
clojail.core/sandbox ([tester & {:keys [timeout namespace context | |
jvm?], :or {timeout 10000, namespace (gensym "sandbox"), context (-> | |
(empty-perms-list) domain context), jvm? true}}]) This function | |
creates a new sandbox from a tester (a set of symbols that make up a | |
blacklist and possibly a whitelist) and optional arguments. A | |
tester can either be a plain set of symbols, in which case it'll be | |
treated as a blacklist. Otherwise, you can provide a map of :whitelist | |
and :blacklist bound to sets. In this case, the whitelist and | |
blacklist will both be used. If you only want a whitelist, just | |
supply :whitelist in the map. Optional arguments are as follows: | |
:timeout, default is 10000 MS or 10 seconds. If the expression | |
evaluated in the sandbox takes longer than the timeout, an error | |
will be thrown and the thread running the code will be stopped. | |
:namespace, the namespace of the sandbox. The default is (gensym | |
"sandbox"). :context, the context for the JVM sandbox to run in. | |
Only relevant if :jvm? is true. It has a sane default, so you | |
shouldn't need to worry about this. :jvm?, if set to true, the JVM | |
sandbox will be employed. It defaults to true. This function will | |
return a new function that you should bind to something. You can call | |
this function with code and it will be evaluated in the sandbox. | |
The function also takes an optional second parameter which is a | |
hashmap of vars to values that will be passed to push-thread-bindings. | |
Example: (def sb (sandbox #{'alter-var-root 'java.lang.Thread} | |
:timeout 5000)) (let [writer (java.io.StringWriter.)] | |
(sb '(println "blah") {#'*out* writer}) (str writer)) The above | |
example returns "blah\n" nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment