Skip to content
Safe ruby code execution in a standard ruby environment. Does not use a chroot, jail, etc. No special permissions required.
Latest commit a4489f8 Mar 10, 2016 @duckinator Name change.



Safe execution environment for untrusted Ruby code.

Build Status Code Coverage Code Climate Dependencies Stories in Ready


gem install sicuro


Sicuro safely executes untrusted ruby code without any complex configuration, unjustifiable permissions (such as passwordless sudo), chroots, or BSD Jails.


If you wish to set the memory or time limits, you will need to manually create a Sicuro instance:

s =, timelimit)

memlimit is in megabytes, and timelimit is in seconds. The defaults are 50MB RAM and 5 seconds.

There is no way to alter the strength of the sandbox.

Running code in the sandbox

Sicuro.eval(code) is an alias for, and returns a Sicuro::Evaluation instance.


Sicuro::Evaluation#code is the code passed to Sicuro#eval.

Sicuro::Evaluation#stdout is anything printed to stdout by the evaluated code (puts, print, etc).

Sicuro::Evaluation#stderr is anything printed to stderr by the evaluated code (warn).

Sicuro::Evaluation#return is the returned value of the last statement.

Sicuro::Evaluation#to_s intelligently returns one of #stdout or #stderr.

Notes on Sicuro::Evaluation#return

Previously, Sicuro provided a #return method that would give the value returned by the last line of code it evaluated. It existed from v0.0.1 to v0.18.0 (inclusive), and was removed with v0.19.0. The way this was accomplished was by returning a JSON object from the child (sandboxed) process to the parent (non-sandboxed) process. However, this approach led to bugs with errors about encoding things to JSON being intermixed with the other results, which gave rather bizarre errors when reaching the parent process.

I plan to eventually either reintroduce this exact functionality in a more robust form, or replace it with a better alternative later on.


Example 1:

require 'sicuro'

s = Sicuro.eval('puts "hi!"')
s.code      # returns "puts \"hi!\""
s.stdout    # returns "hi!\n"
s.stderr    # returns ""
s.to_s      # returns "hi!\n", because it uses #stdout

Example 2:

require 'sicuro'

s = Sicuro.eval('"hi!"')
s.code      # returns "\"hi!\""
s.stdout    # returns ""
s.stderr    # returns ""
s.to_s      # returns "\"hi!\"", because it uses #return compatibility

Sicuro is now API-compatible with the gem.

require 'sicuro'

p, "puts 'lawl'")

# Example output:
#   #<Sicuro::Evaluation code="puts 'lawl'" stdout="lawl\n" stderr="" wall_time=36>


Sicuro is released under the ISC license. See the LICENSE file which should have been distributed with this for more information.

Something went wrong with that request. Please try again.