First, make sure you require "sandbox" before you load any gems.
The Sandbox has three important class methods you should know about.
- Sandbox::load
- Sandbox::ref
- Sandbox::import
To clarify what we're talking about, we'll be distinguishing between "the Sandbox" and "the Jungle".
Objects that live and run within "the Sandbox" do not live in "the Jungle" and vice versa.
Sandbox::load, as you might guess, performs the equivalent of a Kernel#load, but loads the code into the Sandbox rather than the Jungle.
Sandbox::ref lets objects living within the sandbox refer to objects that live /outside/ the sandbox (in da Jungle).
Sandbox::import allows the sandbox to make use of classes, such as URI::HTTP or Hpricot, which have been previously defined somewhere in the Jungle.
Example:
Tepee::Box = Sandbox.safe
Tepee::Box.load "support/markup.rb"
Tepee::Box.ref Web # Web is a module defined in the Jungle
Tepee::Box.import URI::HTTP
%w(Hpricot JSON).each { |klass| Tepee::Box.import Kernel.const_get(klass) }
