local

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 24 Imported by: 9

Documentation

Overview

Package local provides a CodeExecutor that executes code blocks in the local environment. It supports Python and Bash scripts by writing them to files and invoking the appropriate interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeExecutor

type CodeExecutor struct {
	WorkDir        string
	Timeout        time.Duration
	CleanTempFiles bool
	// contains filtered or unexported fields
}

CodeExecutor that executes code on the local host (unsafe).

func New

func New(options ...CodeExecutorOption) *CodeExecutor

New creates a local CodeExecutor.

func (*CodeExecutor) Cleanup added in v0.5.0

func (e *CodeExecutor) Cleanup(
	ctx context.Context, ws codeexecutor.Workspace,
) error

Cleanup delegates to the local workspace runtime.

func (*CodeExecutor) CodeBlockDelimiter

func (e *CodeExecutor) CodeBlockDelimiter() codeexecutor.CodeBlockDelimiter

CodeBlockDelimiter returns the code block delimiter used by the local executor.

func (*CodeExecutor) Collect added in v0.5.0

func (e *CodeExecutor) Collect(
	ctx context.Context, ws codeexecutor.Workspace,
	patterns []string,
) ([]codeexecutor.File, error)

Collect delegates to the local workspace runtime.

func (*CodeExecutor) CreateWorkspace added in v0.5.0

func (e *CodeExecutor) CreateWorkspace(
	ctx context.Context, execID string,
	pol codeexecutor.WorkspacePolicy,
) (codeexecutor.Workspace, error)

CreateWorkspace delegates to the local workspace runtime.

func (*CodeExecutor) Engine added in v0.5.0

func (e *CodeExecutor) Engine() codeexecutor.Engine

Engine exposes the local runtime as an Engine for skills.

func (*CodeExecutor) ExecuteCode

ExecuteCode executes code blocks and returns combined output.

func (*CodeExecutor) ExecuteInline added in v0.5.0

func (e *CodeExecutor) ExecuteInline(
	ctx context.Context, execID string,
	blocks []codeexecutor.CodeBlock,
	timeout time.Duration,
) (codeexecutor.RunResult, error)

ExecuteInline delegates to the local workspace runtime.

func (*CodeExecutor) PutDirectory added in v0.5.0

func (e *CodeExecutor) PutDirectory(
	ctx context.Context, ws codeexecutor.Workspace,
	hostPath, to string,
) error

PutDirectory delegates to the local workspace runtime.

func (*CodeExecutor) PutFiles added in v0.5.0

func (e *CodeExecutor) PutFiles(
	ctx context.Context, ws codeexecutor.Workspace,
	files []codeexecutor.PutFile,
) error

PutFiles delegates to the local workspace runtime.

func (*CodeExecutor) RunProgram added in v0.5.0

RunProgram delegates to the local workspace runtime.

type CodeExecutorOption

type CodeExecutorOption func(*CodeExecutor)

CodeExecutorOption configures a local CodeExecutor.

func WithCleanTempFiles

func WithCleanTempFiles(clean bool) CodeExecutorOption

WithCleanTempFiles toggles cleanup of temporary helper files.

func WithCodeBlockDelimiter added in v0.6.0

func WithCodeBlockDelimiter(
	delimiter codeexecutor.CodeBlockDelimiter,
) CodeExecutorOption

WithCodeBlockDelimiter sets the code block delimiter.

func WithTimeout

func WithTimeout(timeout time.Duration) CodeExecutorOption

WithTimeout sets the per-command timeout.

func WithWorkDir

func WithWorkDir(workDir string) CodeExecutorOption

WithWorkDir sets the working directory used for execution.

func WithWorkspaceAutoInputs added in v0.6.0

func WithWorkspaceAutoInputs(enable bool) CodeExecutorOption

WithWorkspaceAutoInputs enables or disables automatic mapping of the host inputs directory (when configured) into work/inputs for each workspace.

func WithWorkspaceInputsHostBase added in v0.6.0

func WithWorkspaceInputsHostBase(host string) CodeExecutorOption

WithWorkspaceInputsHostBase sets the host inputs directory that will be exposed under work/inputs when auto inputs are enabled.

func WithWorkspaceMode added in v1.3.0

func WithWorkspaceMode(mode WorkspaceMode) CodeExecutorOption

WithWorkspaceMode configures how local workspaces are created.

The default is WorkspaceModeIsolated, which creates a unique workspace per run. WorkspaceModeTrustedLocal reuses WorkDir as the workspace root.

type Runtime added in v0.5.0

type Runtime struct {
	WorkRoot            string
	ReadOnlyStagedSkill bool
	InputsHostBase      string
	AutoInputs          bool
	Mode                WorkspaceMode
}

Runtime implements the workspace-based executor using local processes.

func NewRuntime added in v0.5.0

func NewRuntime(workRoot string) *Runtime

NewRuntime creates a new local Runtime. When workRoot is empty, a temporary directory will be used per workspace.

func NewRuntimeWithOptions added in v0.5.0

func NewRuntimeWithOptions(
	workRoot string, opts ...RuntimeOption,
) *Runtime

NewRuntimeWithOptions creates a Runtime with optional settings.

func (*Runtime) Cleanup added in v0.5.0

func (r *Runtime) Cleanup(
	ctx context.Context,
	ws codeexecutor.Workspace,
) error

Cleanup removes workspace directory if it exists.

func (*Runtime) Collect added in v0.5.0

func (r *Runtime) Collect(
	ctx context.Context,
	ws codeexecutor.Workspace,
	patterns []string,
) ([]codeexecutor.File, error)

Collect finds output files by glob patterns relative to workspace root.

func (*Runtime) CollectOutputs added in v0.5.0

CollectOutputs implements the declarative collector with limits.

func (*Runtime) CreateWorkspace added in v0.5.0

func (r *Runtime) CreateWorkspace(
	ctx context.Context,
	execID string,
	pol codeexecutor.WorkspacePolicy,
) (codeexecutor.Workspace, error)

CreateWorkspace creates an execution workspace directory.

func (*Runtime) ExecuteInline added in v0.5.0

func (r *Runtime) ExecuteInline(
	ctx context.Context,
	execID string,
	blocks []codeexecutor.CodeBlock,
	timeout time.Duration,
) (codeexecutor.RunResult, error)

ExecuteInline writes temp files for code blocks and runs them.

func (*Runtime) PutDirectory added in v0.5.0

func (r *Runtime) PutDirectory(
	ctx context.Context,
	ws codeexecutor.Workspace,
	hostPath string,
	to string,
) error

PutDirectory copies an entire directory from host into workspace.

func (*Runtime) PutFiles added in v0.5.0

func (r *Runtime) PutFiles(
	ctx context.Context,
	ws codeexecutor.Workspace,
	files []codeexecutor.PutFile,
) error

PutFiles writes file blobs under the workspace root.

func (*Runtime) RunProgram added in v0.5.0

RunProgram runs a command inside the workspace.

func (*Runtime) StageDirectory added in v0.5.0

func (r *Runtime) StageDirectory(
	ctx context.Context,
	ws codeexecutor.Workspace,
	src string,
	to string,
	opt codeexecutor.StageOptions,
) error

StageDirectory stages a host directory into the workspace. Behavior depends on options, e.g., making the tree read-only.

func (*Runtime) StageInputs added in v0.5.0

func (r *Runtime) StageInputs(
	ctx context.Context,
	ws codeexecutor.Workspace,
	specs []codeexecutor.InputSpec,
) error

StageInputs maps external inputs into the workspace.

func (*Runtime) StartProgram added in v1.7.0

StartProgram starts an interactive program in the workspace.

type RuntimeOption added in v0.5.0

type RuntimeOption func(*Runtime)

RuntimeOption customizes the local Runtime behavior.

func WithAutoInputs added in v0.6.0

func WithAutoInputs(enable bool) RuntimeOption

WithAutoInputs enables or disables automatic mapping of the host inputs directory (when configured) into work/inputs for each workspace.

func WithInputsHostBase added in v0.6.0

func WithInputsHostBase(host string) RuntimeOption

WithInputsHostBase sets the host directory that will be exposed under work/inputs inside each workspace when auto inputs are enabled.

func WithReadOnlyStagedSkill added in v0.5.0

func WithReadOnlyStagedSkill(readOnly bool) RuntimeOption

WithReadOnlyStagedSkill toggles making staged skill trees read-only.

func WithRuntimeWorkspaceMode added in v1.3.0

func WithRuntimeWorkspaceMode(mode WorkspaceMode) RuntimeOption

WithRuntimeWorkspaceMode sets the workspace mode for the runtime.

type WorkspaceMode added in v1.3.0

type WorkspaceMode int

WorkspaceMode controls how the local runtime chooses workspace roots.

const (
	// WorkspaceModeIsolated creates a unique workspace directory for each
	// CreateWorkspace call. This is the default and is safer.
	WorkspaceModeIsolated WorkspaceMode = iota
	// WorkspaceModeTrustedLocal reuses WorkRoot as the workspace root.
	// Cleanup becomes a no-op to avoid deleting user directories.
	WorkspaceModeTrustedLocal
)

Jump to

Keyboard shortcuts

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