runshell

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package runshell implements the sandboxed run_shell tool definition and executor. The unsandboxed run_unsafe_shell tool lives in internal/tools/rununsafeshell.

Execute runs a bash command inside the sandbox. Output is truncated at maxOutputBytes (preserving valid UTF-8 boundaries) and each command is killed after commandTimeout.

Index

Constants

View Source
const (
	// CommandTimeout is the maximum wall-clock time a single shell
	// command is allowed to run before being killed.
	CommandTimeout = 30 * time.Second

	// MaxOutputBytes limits captured stdout+stderr to avoid sending
	// excessively large tool results back to the API.
	MaxOutputBytes = 10240
)
View Source
const ToolName = "run_shell"

ToolName is the model-facing name of the sandboxed shell tool.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, sb sandbox.Sandbox, command string, restart bool, timeoutSeconds int) (output string, isError bool)

Execute runs a sandboxed shell command. If restart is true, command is ignored and a restart acknowledgment is returned. timeoutSeconds is the per-invocation override in seconds; zero or negative falls back to CommandTimeout (see Timeout). Errors from the underlying process surface as (output, isError=true); timeout output is substituted for the command's own output when the deadline fires.

func Run

func Run(ctx context.Context, cmd *exec.Cmd, timeout time.Duration) (string, bool)

Run executes cmd, killing it if ctx fires before it finishes. timeout is the effective timeout used only to render an accurate "Command timed out" message; the actual deadline is enforced by ctx. The returned output combines stdout+stderr, truncated at MaxOutputBytes on a valid UTF-8 boundary. Exported so internal/tools/rununsafeshell and internal/tools/skill can reuse it.

func Timeout

func Timeout(seconds int) time.Duration

Timeout returns the effective per-command timeout: seconds converted to a time.Duration capped at maxTimeout (30m) when positive, or CommandTimeout as the default when seconds is zero or negative. This is the single source of the "override or default" decision, shared by run_shell and run_unsafe_shell.

func ToolDef

func ToolDef() tooldef.Definition

ToolDef returns the jungi tool definition for the sandboxed shell.

Types

type Tool

type Tool struct {
	// contains filtered or unexported fields
}

Tool implements tool.Tool for the run_shell tool. It binds the sandbox the command runs inside; the per-invocation command and restart flag come from the request (pre-parsed by the client into Command/Restart).

func New

func New(sb sandbox.Sandbox) *Tool

New returns a run_shell Tool that runs commands inside sb.

func (*Tool) Definition

func (*Tool) Definition() tooldef.Definition

Definition delegates to the package-level ToolDef so the advertised definition stays identical whether or not a Tool has been constructed.

func (*Tool) Execute

func (t *Tool) Execute(ctx context.Context, req message.ToolUseRequest) tool.Result

Execute runs the command (or restarts the session) and labels the event: the restart variant is surfaced via Variant; otherwise the command is the Subject. Display equals the model output.

func (*Tool) Preview added in v0.2.1

func (*Tool) Preview(req message.ToolUseRequest) (string, string)

Preview returns the restart variant or the command subject from the request so the start history line matches completion.

Source Files

  • proc_unix.go
  • runshell.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL