I want to be able to run unstrusted ruby code. I want to be able to pass variables to said untrusted code that it may use. I also want said code to return a result to me. Here is a conceptual example of what I am thinking
input = "sweet"
output = nil
Thread.start {
$SAFE = 4
#... untrusted code goes here, it uses the input variable(s)
#to calculate some result that it places in the output variable
}
#parse the output variable as a string.
Just to clarify, I am basically using the untrusted code as a function. I want to provide its some inputs, and then allow it to write to the output. That is all I really want, I don't care how it is done, I just want the ability to use untrusted Ruby code as a sort of function. The solution does not have to look anything like the code I wrote above, I am just using it to illustrate what I want.
Now, I can currently think of 3 ways to do this:
- Use the $SAFE level construct above.
- whytheluckystiff has a Sandbox plugin for ruby
- I could run each function in its own virtual machine, using some sort of os virtualization software like vmware or Xen or something.
I am wondering if anyone has any recommendations for running untrusted ruby code in a functional way? What option would you recomend? How would you go about it? Thanks.