{"id":15586320,"url":"https://github.com/alecdotninja/ruby_box","last_synced_at":"2025-07-04T14:35:37.431Z","repository":{"id":56893353,"uuid":"69086181","full_name":"alecdotninja/ruby_box","owner":"alecdotninja","description":"RubyBox allows the execution of untrusted Ruby code safely in a sandbox.","archived":false,"fork":false,"pushed_at":"2017-03-11T00:20:28.000Z","size":35,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-03T21:58:37.150Z","etag":null,"topics":["opal","ruby","ruby-box","sandbox"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alecdotninja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-24T06:58:48.000Z","updated_at":"2025-01-20T22:41:16.000Z","dependencies_parsed_at":"2022-08-20T16:10:39.180Z","dependency_job_id":null,"html_url":"https://github.com/alecdotninja/ruby_box","commit_stats":null,"previous_names":["anarchocurious/ruby_box"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/alecdotninja/ruby_box","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecdotninja%2Fruby_box","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecdotninja%2Fruby_box/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecdotninja%2Fruby_box/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecdotninja%2Fruby_box/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alecdotninja","download_url":"https://codeload.github.com/alecdotninja/ruby_box/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alecdotninja%2Fruby_box/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263557128,"owners_count":23480113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opal","ruby","ruby-box","sandbox"],"created_at":"2024-10-02T21:21:51.729Z","updated_at":"2025-07-04T14:35:37.373Z","avatar_url":"https://github.com/alecdotninja.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RubyBox\n\n[![Gem Version](https://badge.fury.io/rb/ruby_box.svg)](https://badge.fury.io/rb/ruby_box) [![Build Status](https://travis-ci.org/anarchocurious/ruby_box.svg?branch=master)](https://travis-ci.org/anarchocurious/ruby_box) [![Code Climate](https://codeclimate.com/github/anarchocurious/ruby_box/badges/gpa.svg)](https://codeclimate.com/github/anarchocurious/ruby_box) [![Test Coverage](https://codeclimate.com/github/anarchocurious/ruby_box/badges/coverage.svg?break-cache-again)](https://codeclimate.com/github/anarchocurious/ruby_box/coverage) [![Security](https://hakiri.io/github/anarchocurious/ruby_box/master.svg)](https://hakiri.io/github/anarchocurious/ruby_box/master)\n\nRubyBox allows the execution of untrusted Ruby code safely in a sandbox. It works by compiling Ruby code to JavaScript using [`opal`](https://github.com/opal/opal) and executing it in [Google's V8 Engine](https://github.com/cowboyd/libv8) with some help from [`mini_racer`](https://github.com/discourse/mini_racer).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'ruby_box'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ruby_box\n\n## Usage\n\n```ruby\n# `RubyBox::Metal` is the sandbox base class. It has only the bare essentials to get the environment working.\nclass MySandbox \u003c RubyBox::Metal\n  # Code in the sandbox will block at most one second\n  times_out_in 1.second\n\n  # Makes the opal gem available for requiring inside the sandbox\n  uses 'opal'\n\n  # Requires the Opal compiler inside the sandbox (enables advanced runtime meta-programming like `Kernel#eval`)\n  requires 'opal-parser'\n\n  # Exposes the #native_add method to code running inside the sandbox\n  exposes :native_add\n\n  # Executes some code in the sandbox to setup it's runtime state\n  executes \u003c\u003c-RUBY\n    $global_state = 1337\n\n    # Some boilerplate code\n    class PlayThing\n      attr_reader :name\n    \n      def initialize(name)\n        @name = name\n      end\n\n      # Code inside of the sandbox can get a handle on the box with `RubyBox.current` and call exposed methods\n      def add(a, b)\n        RubyBox.current.native_add(a, b)\n      end\n    end\n  RUBY\n\n  def native_add(a, b)\n    a + b\n  end\nend\n\nuntrusted_program = \u003c\u003c-RUBY\n  $global_state = 'tainted'\n\n  puts \"Hello, world\"\n  \n  car = PlayThing.new(\"Car\")\n  car.name\nRUBY\n\n# Every instance of the sandbox starts with the state configured on the class\nmy_sandbox = MySandbox.new\nmy_sandbox.execute(untrusted_program) #=\u003e \"Car\"\nmy_sandbox.execute('PlayThing.add(2,7)') #=\u003e 9\nmy_sandbox.stdout #=\u003e [\"Hello, world\\n\"]\n\n# Every instance of the sandbox is isolated\nanother_sandbox = MySandbox.new\nanother_sandbox.execute('$global_state') #=\u003e 1337\n\n# It also has an stderr\nanother_sandbox.execute('warn \"This looks dangerous\"')\nanother_sandbox.stderr #=\u003e [\"This looks dangerous\\n\"]\n\n# Exceptions comes through as subclasses of RubyBox::BoxedError\nanother_sandbox.execute('nil.no_method') #=\u003e RubyBox::BoxedError::BoxedNoMethodError\n\n# You can determine if you are in a sandbox using `RubyBox.boxed?` and `RubyBox.current`\nRubyBox.boxed? #=\u003e false\nRubyBox.current #=\u003e nil\n```\n\n## Development\n\nThe development dependencies of this gem are managed using [Bundler](https://rubygems.org/gems/bundler).\n\nAfter checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bundle exec rake console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [RubyGems](https://rubygems.org/gems/ruby_box).\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/anarchocurious/ruby_box).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecdotninja%2Fruby_box","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falecdotninja%2Fruby_box","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falecdotninja%2Fruby_box/lists"}