Class: RubyLLM::Toolbox::Tools::RunRust

Inherits:
Base
  • Object
show all
Includes:
SandboxRun
Defined in:
lib/ruby_llm/toolbox/tools/run_rust.rb

Overview

EXEC. Compiles and runs a Rust snippet inside the hardened Docker sandbox (no network, read-only root with a tmpfs scratch, dropped capabilities, resource/time limits). The source is piped on stdin; a tiny shell step inside the (already isolated) container writes it to the tmpfs, compiles with rustc, and runs the binary.

Gated: requires config.enable_exec_tools AND Docker on the host. Uses config.rust_image (default rust:1-slim).

Constant Summary collapse

COMPILE_AND_RUN =

cat the piped source into the tmpfs, compile, then run.

"cat > /tmp/m.rs && rustc -O /tmp/m.rs -o /tmp/m 2>&1 && /tmp/m"

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods included from SandboxRun

#format_sandbox, #run_in_sandbox

Methods inherited from Base

#call, exec_tool!, exec_tool?, #initialize, #name

Constructor Details

This class inherits a constructor from RubyLLM::Toolbox::Base

Instance Method Details

#execute(code:) ⇒ Object



34
35
36
37
38
# File 'lib/ruby_llm/toolbox/tools/run_rust.rb', line 34

def execute(code:)
  return error("code must be provided", code: :empty_code) if code.to_s.strip.empty?

  run_in_sandbox(["sh", "-c", COMPILE_AND_RUN], code, image: config.rust_image)
end