class LittleGhost::Tools::Shell
Shell lets an agent run a command through the configured Sandbox.
By default it accepts an argument vector, so model-supplied values are not interpreted as shell syntax, and each command may run for 30 seconds. Subclass it to accept a shell command string or to let the model choose a bounded timeout:
class SupportShell < LittleGhost::Tools::Shell command_mode :string timeout default: 120, maximum: 900 exclusive true end
The child environment is cleared and each output stream is limited to 1 MB unless #max_output_bytes is configured. Commands may spawn children when the backend supports them. These defaults reduce accidental exposure but do not create an isolation boundary; the configured Sandbox remains responsible for security.
Public Class Methods
# File lib/little_ghost/tools/shell.rb, line 48 def command_mode(*values) return command_mode_value if values.empty? mode = values.fetch(0).to_sym raise ArgumentError, "command_mode must be one of #{COMMAND_MODES.join(", ")}" unless COMMAND_MODES.include?(mode) self.command_mode_value = mode end
Selects how the model supplies a command. :argv accepts an array of arguments and runs the executable directly. :string accepts one command string and runs it with /bin/sh -c, so pipes, redirection, and variable expansion apply inside the Sandbox.
Raises ArgumentError for any other mode.
# File lib/little_ghost/tools/shell.rb, line 83 def max_output_bytes(*values) return max_output_bytes_value if values.empty? self.max_output_bytes_value = positive_integer(values.fetch(0), "max_output_bytes") end
The per-stream output limit passed to the Sandbox.
# File lib/little_ghost/tools/shell.rb, line 67 def timeout(default:, maximum: nil) default = positive_integer(default, "timeout default") maximum = positive_integer(maximum, "timeout maximum") unless maximum.nil? if maximum && default > maximum raise ArgumentError, "timeout default must not exceed timeout maximum" end self.timeout_maximum_value = maximum self.timeout_default_value = default end
Sets the command timeout in seconds. With maximum, the input schema gains an optional timeout_seconds argument the model may set between 1 and maximum; omitted, null, or zero values use default. Without maximum, every command uses default.
Raises ArgumentError unless both values are positive integers and default does not exceed maximum.
Public Instance Methods
Source
# File lib/little_ghost/tools/shell.rb, line 143 def call(input) options = { timeout: timeout_for(input), context:, max_output_bytes: self.class.max_output_bytes, environment: {}, inherit_environment: false } result = if self.class.command_mode == :string sandbox.execute(input.fetch("command"), **options) else sandbox.execute_program(input.fetch("command"), **options) end output = { stdout: result.stdout, stderr: result.stderr, exit_status: result.exit_code, success: result.success? } output[:error] = execution_error(result.error) if result.error JSON.generate(output) end
Executes input["command"] and returns a JSON result containing standard output, standard error, exit status, and success. When the Sandbox reports an execution error, the result adds an error message that names only the exception class; the errorโs own message stays out of model-visible output.
Source
# File lib/little_ghost/tools/shell.rb, line 166 def description self.class.description_value || framework_prompt("tools/built_in/shell/description", **self.class.description_locals) end