Module: RubyLLM::Toolbox::Sandbox
- Defined in:
- lib/ruby_llm/toolbox/sandbox/base.rb,
lib/ruby_llm/toolbox/sandbox/docker.rb,
lib/ruby_llm/toolbox/sandbox/bubblewrap.rb,
lib/ruby_llm/toolbox/sandbox/sandbox_exec.rb
Overview
Pluggable sandboxes for the code-execution tools (run_ruby/run_python/ run_rust). Each backend exposes the same contract:
available? -> true if it can run here
run(argv, stdin:, image: nil) -> [stdout, stderr, status]
command(argv, image: nil) -> the fully wrapped argv (for tests)
‘image` is only meaningful for Docker; the host-process sandboxes (Bubblewrap, sandbox-exec) ignore it and run the host’s interpreters.
Sandbox.build(config) returns the active backend based on config.sandbox_runtime (:auto by default): on Linux it prefers bubblewrap, on macOS sandbox-exec, falling back to Docker, then to a Null backend that reports unavailability cleanly.
Defined Under Namespace
Classes: Base, Bubblewrap, Docker, Null, SandboxExec, Unavailable
Class Method Summary collapse
- .build(config) ⇒ Object
-
.detect(config) ⇒ Object
:auto — first available backend, preferring the native lightweight sandbox for the platform, then Docker.
- .host_os ⇒ Object
- .linux? ⇒ Boolean
- .macos? ⇒ Boolean
Class Method Details
.build(config) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby_llm/toolbox/sandbox/base.rb', line 38 def build(config) case config.sandbox_runtime when :docker then Docker.new(config) when :bubblewrap then Bubblewrap.new(config) when :sandbox_exec then SandboxExec.new(config) when :none then Null.new(config) else detect(config) end end |
.detect(config) ⇒ Object
:auto — first available backend, preferring the native lightweight sandbox for the platform, then Docker.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby_llm/toolbox/sandbox/base.rb', line 50 def detect(config) candidates = if macos? [SandboxExec, Docker] elsif linux? [Bubblewrap, Docker] else [Docker] end candidates.each do |klass| backend = klass.new(config) return backend if backend.available? end Null.new(config) end |
.host_os ⇒ Object
26 27 28 |
# File 'lib/ruby_llm/toolbox/sandbox/base.rb', line 26 def host_os RbConfig::CONFIG["host_os"].to_s end |
.linux? ⇒ Boolean
30 31 32 |
# File 'lib/ruby_llm/toolbox/sandbox/base.rb', line 30 def linux? host_os.include?("linux") end |
.macos? ⇒ Boolean
34 35 36 |
# File 'lib/ruby_llm/toolbox/sandbox/base.rb', line 34 def macos? host_os =~ /darwin|mac os/ ? true : false end |