Class: RubyLLM::Toolbox::Tools::RunPython

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

Overview

EXEC. Executes a Python snippet inside a hardened Docker container (no network, read-only filesystem, dropped capabilities, memory/CPU/pids limits, wall-clock timeout). Source is piped to the interpreter on stdin, so nothing from the host is mounted.

Gated: requires config.enable_exec_tools AND Docker on the host. Uses config.python_image (default python:3.12-slim).

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



30
31
32
33
34
# File 'lib/ruby_llm/toolbox/tools/run_python.rb', line 30

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

  run_in_sandbox(["python3", "-"], code, image: config.python_image)
end