Class: Nexo::Tools::Shell

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/nexo/tools/shell.rb

Overview

Runs a shell command in the agent's sandbox. Authorizes :shell first. A denial, or a sandbox with no shell (e.g. Sandboxes::Virtual), is returned as { error: ... } rather than raised into the loop.

Instance Method Summary collapse

Constructor Details

#initialize(sandbox:, permissions:) ⇒ Shell

sandbox runs the command; permissions gates the :shell capability.



13
14
15
16
17
# File 'lib/nexo/tools/shell.rb', line 13

def initialize(sandbox:, permissions:)
  @sandbox = sandbox
  @permissions = permissions
  super()
end

Instance Method Details

#execute(command:) ⇒ Object

Authorizes :shell, runs command, and returns +{ stdout:, stderr:, status: }+ (stdout/stderr truncated via OutputTruncator) — or { error: ... } on a denial or a sandbox with no shell.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nexo/tools/shell.rb', line 22

def execute(command:)
  @permissions.authorize!(:shell, command)
  out = @sandbox.shell(command)
  {
    stdout: OutputTruncator.call(out[:stdout]),
    stderr: OutputTruncator.call(out[:stderr]),
    status: out[:status]
  }
rescue Permissions::Denied, NotImplementedError => e
  {error: e.message}
end