module RubyLLM::Sandbox
A sandbox runs commands RubyLLM did not write, such as the code a model sends to Chat#with_code_execution, where they cannot read your project, your home directory, or your secrets. Set one in the configuration:
RubyLLM.configure do |config| config.sandbox = :mxc end
:mxc uses the built-in sandbox on the mxc gem. Any other object that answers two methods works too:
class RemoteSandbox def supported? true end def run(*command, timeout:, readable: [], writable: [], denied: [], network: false, directory: nil, env: {}) # Runs +command+ and returns an object answering stdout, stderr, # exit_code, and timed_out? end end
run takes the command like Kernel#system: one String for the shell, or a program and its arguments. readable and writable are paths on this machine the command may read, or read and change, and denied paths it must not see, even inside readable ones. network is false, true, or { allow: ["pypi.org"] }. directory is where the command starts and env the only environment variables it gets. The result may also answer blocked, the hosts the network policy refused. A sandbox may answer reason, which RubyLLM adds to the error it raises when #supported? is false.