lördag, december 02, 2006

Freaky freaky Sandbox has come to JRuby

I would like to announce the first release of JavaSand, which brings _why's spooky Sandbox to JRuby.

For those of you who hasn't played with Sandbox, it allows you to create a new area for executing Ruby where you have control on which classes are loaded and available. It's good for lots of things. It can be made very secure, for example. Or you can load several applications in different Sandboxes and they won't interfere with each other in any way.

Now, in MRI, this is done through some fairly involved swapping of symbol tables. In JRuby things are quite a lot easier. Actually, it's only a matter of loading the right classes and remove all methods not allowed.

So, how do you get to use sandbox from JRuby? First of all, you need a special JRuby, that can be checked out and compiled from svn://svn.codehaus.org/jruby/branches/sandbox. This functionality will come to regular JRuby to, but not until after 0.9.2 has been released. So, when you have this special version downloaded, you just install the RubyGem called javasand, and you're set to go. If you would like a fun example to try out, you can download sandbox_server directly from _why's code repository http://code.whytheluckystiff.net/svn/sandbox/trunk/bin/sandbox_server. To run it:
jruby -rubygems sandbox_server
and you can connect to your machine at port 5000, press enter, and you have an IRB session. Wow!

So, the project JavaSand is part of JRuby-extras and the source is in that repository, at RubyForge! Go ahead and test it now!

1 kommentar:

Molotoff sa...

I've installed javasand on jruby 1.0.3 and I can require 'sandbox' but Sandbox.new produces an error:

/usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:70:in `signal_status': assigning non-exception to $! (TypeError)
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:147:in `eval_input'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:146:in `loop'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:146:in `catch'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:146:in `eval_input'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:70:in `start'
from :1:in `catch'
from /usr/local/jruby-1.0.3/lib/ruby/1.8/irb.rb:69:in `start'
from :1

I've also tried using RC2, but was not even able to 'require' the sandbox.

It would be cool, if you had some suggestions on how to get it going.