This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/tools/shell.go

39 lines
930 B
Go

package tools
import (
"context"
"encoding/json"
"fmt"
"ollie/toolsrv"
)
// Shell executes a single bash command in a sandboxed environment.
func Shell(ctx context.Context, srv *toolsrv.Server, args json.RawMessage) (string, error) {
var a struct {
Cmd string `json:"cmd"`
Timeout int `json:"timeout"`
Sandbox string `json:"sandbox"`
Elevated bool `json:"elevated"`
Detach bool `json:"detach"`
}
if err := json.Unmarshal(args, &a); err != nil {
return "", fmt.Errorf("shell: bad args: %w", err)
}
if a.Cmd == "" {
return "", fmt.Errorf("shell: cmd is required")
}
timeout := a.Timeout
if timeout <= 0 {
timeout = 30
}
if a.Elevated {
return srv.ExecuteElevated(ctx, a.Cmd, srv.CWD(), timeout, a.Detach)
}
sandboxName := a.Sandbox
if sandboxName == "" {
sandboxName = "default"
}
return srv.ExecuteInSandbox(ctx, a.Cmd, "bash", timeout, sandboxName, false, "", a.Detach)
}