sandboxtools

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sandboxtools exposes the thread sandbox to the model: execute_command (with background jobs: job_output, job_kill), read_file (text, documents, images), view_file (rendered pages), search_files, write_file, edit_file and list_files.

Index

Constants

View Source
const NoVisionError = "this model cannot view images; use read_file and the skill's inspect script"

NoVisionError is the view_file error for models that cannot see images.

View Source
const RecreatedNotice = "Notice: the sandbox stopped or stayed unresponsive and has been recreated; /workspace was reset and previous files are gone."

RecreatedNotice tells the model its previous sandbox was replaced.

View Source
const RemovedJobNote = "" /* 242-byte string literal not displayed */

RemovedJobNote is the stderr of a command that deleted its own job directory (%s: the directory, %d: the exit code). Round 3, A11.

View Source
const StaleFileError = "file changed since you last read it; read it again"

StaleFileError is the edit_file error for a file changed since the model last saw it.

Variables

This section is empty.

Functions

func ExtractText

func ExtractText(ctx context.Context, sb sandbox.Sandbox, p string, maxChars int) (string, error)

ExtractText returns up to maxChars characters of a file's text: documents through the extraction script (markitdown, pdftotext), text files as they are; images and other binaries give "" (the goal judge's deliverable excerpt).

Types

type JobList

type JobList = sandbox.JobList

ListedJob and JobList are the background-job registry port (core/sandbox).

type ListedJob

type ListedJob = sandbox.ListedJob

ListedJob and JobList are the background-job registry port (core/sandbox).

type Options

type Options struct {
	// CommandTimeout is the default execute_command timeout (default 120 s).
	CommandTimeout time.Duration
	// MaxSandboxesPerUser is only used in the quota error message.
	MaxSandboxesPerUser int
	// OnAcquire runs after every successful sandbox acquisition (installs the skills the run needs).
	OnAcquire func(ctx context.Context, rc tools.RunContext, sb sandbox.Sandbox)
	// BeforeCommand runs before every execute_command command (foreground or
	// background job) starts, e.g. to install the skills it names
	// (/skills/<name>/). A sandbox found gone fails the call (retried on a new
	// sandbox); other errors are logged and the command runs.
	BeforeCommand func(ctx context.Context, rc tools.RunContext, sb sandbox.Sandbox, command string) error
	// OnWrite runs after write_file or edit_file wrote content to path (e.g.
	// to install the skills the content names); its errors are logged.
	OnWrite func(ctx context.Context, rc tools.RunContext, sb sandbox.Sandbox, path string, content []byte) error
	// CheckWrite runs after write_file or edit_file wrote path; a non-empty result
	// (a syntax error, say) is added to the tool result as its notice.
	CheckWrite func(ctx context.Context, sb sandbox.Sandbox, path string) string
	// AfterPath runs after read_file, write_file or edit_file succeeded on path (an absolute sandbox path); a
	// non-empty result is appended to the tool result (the notes of the directory the file is in).
	// It runs at most once per call and must be cheap when it has nothing to say.
	AfterPath func(ctx context.Context, rc tools.RunContext, sb sandbox.Sandbox, path string) string
	// AfterFailedCommand runs after a foreground command exited non-zero,
	// with its output (stdout then stderr); a non-empty result is added to the
	// tool result as its note (e.g. "Skill x was installed; run the command
	// again."). The command is never re-run.
	AfterFailedCommand func(ctx context.Context, rc tools.RunContext, sb sandbox.Sandbox, output string) string
	// KeepAlive renews the sandbox of a running background job until stop
	// (jobs.go; default sandbox.KeepAlive).
	KeepAlive func(ctx context.Context, sb sandbox.Sandbox) (stop func())
	// JobPollEvery is how often a kept-alive job's status is checked (default 60 s);
	// JobKeepAliveMax bounds the keep-alive of one job (default 6 h).
	JobPollEvery    time.Duration
	JobKeepAliveMax time.Duration
	// Jobs persists the running background jobs (nil: in memory only, their
	// keep-alives end with the process).
	Jobs JobList
	// Coding describes the tools for a coding agent (AGENT_PROFILE=coding): no
	// document features in read_file, execute_command and the like (coding.go).
	Coding bool
}

Options configures the provider.

type Provider

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

Provider is the sandbox tools provider.

func New

func New(mgr sandbox.Manager, opts Options) *Provider

New returns the provider (nil when the manager is disabled).

func (*Provider) KeepResumingJobs

func (p *Provider) KeepResumingJobs(ctx context.Context, every time.Duration, done func(resumed int))

KeepResumingJobs runs ResumeJobs now and then every `every` until ctx ends: a job whose owner died (its lease expired) is taken over by a live replica.

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) ResumeJobs

func (p *Provider) ResumeJobs(ctx context.Context) int

ResumeJobs re-registers the keep-alive of every listed job still running in its thread's live sandbox that no other process keeps alive (a runtime process start, then periodically: KeepResumingJobs), for what is left of its budget; jobs past their budget, finished or without a sandbox are dropped from the list. It creates no sandbox.

func (*Provider) Tools

func (p *Provider) Tools(_ context.Context, rc tools.RunContext) ([]ai.BaseTool, func(), error)

Tools implements tools.Provider. The sandbox is acquired lazily on first tool call.

Directories

Path Synopsis
Package conformance checks that a sandbox adapter runs the harness' sandbox tools (execute_command with background jobs, read/write/edit/list files, search_files) end to end: the scripts those tools send through sandbox.Sandbox.Exec need bash, GNU coreutils, python3 and ripgrep in the sandbox image (docs/sandbox-adapters.md).
Package conformance checks that a sandbox adapter runs the harness' sandbox tools (execute_command with background jobs, read/write/edit/list files, search_files) end to end: the scripts those tools send through sandbox.Sandbox.Exec need bash, GNU coreutils, python3 and ripgrep in the sandbox image (docs/sandbox-adapters.md).

Jump to

Keyboard shortcuts

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