Skip to content

Instantly share code, notes, and snippets.

@tario
Created October 4, 2013 12:51
Show Gist options
  • Save tario/cab801a8a9fd6cfb0f6e to your computer and use it in GitHub Desktop.
Save tario/cab801a8a9fd6cfb0f6e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "rubygems"
require "shikashi"
include Shikashi
s = Sandbox.new
priv = Privileges.new
# allow execution of foo, print, puts in this object
#priv.object(self).allow :foo, :print, :puts, :new
priv.methods_of(Kernel).allow :puts
priv.methods_of(Class).allow :new
priv.methods_of(Fixnum).allow :+
#inside the sandbox, only can use method foo on main and method times on instances of Fixnum
code = <<-EOS
# class MP
class MP
def calc(a,b)
a + b
end
def test(a)
c = calc(10,20)
puts c
puts "inside test \#{c}"
if (a)
system('ls -l') # denied
end
end
end
#include AtlasMP
#test
MP.new.test(false)
EOS
s.run(code, priv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment