Skip to content

Instantly share code, notes, and snippets.

@tario
Forked from anonymous/shikashi-sandbox.rb
Created October 3, 2013 18:14
Show Gist options
  • Save tario/6814395 to your computer and use it in GitHub Desktop.
Save tario/6814395 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 "inside test "
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