Documentation
¶
Overview ¶
Package computer is a sandboxed computer for an agent: a shell (gbash) over mounted directories, with the tools of an MCP server as commands and as a Python package, jq and sqlite3, and python3 running as WebAssembly. Nothing in it reaches the network or the host, except through those tools and mounts.
Index ¶
- type Computer
- func (c *Computer) About(toolCommands, toolModules []string) string
- func (c *Computer) Close() error
- func (c *Computer) Describe(ctx context.Context) (string, error)
- func (c *Computer) Environment() *Environment
- func (c *Computer) Exec(ctx context.Context, req *gbash.ExecutionRequest) (*gbash.ExecutionResult, error)
- func (c *Computer) MCPServer(ctx context.Context, limit time.Duration) (*mcp.Server, error)
- func (c *Computer) Mounts() []Mount
- func (c *Computer) Options(ctx context.Context) ([]gbash.Option, error)
- func (c *Computer) Session(ctx context.Context) (*gbash.Session, error)
- func (c *Computer) ToolCommands() []string
- func (c *Computer) ToolModules() []string
- type Config
- type Environment
- func (e *Environment) List(ctx context.Context, name string) ([]fs.FileInfo, error)
- func (e *Environment) Mkdir(ctx context.Context, name string, parents bool) error
- func (e *Environment) Read(ctx context.Context, name string, offset, length int64) ([]byte, error)
- func (e *Environment) Remove(ctx context.Context, name string, recursive bool) error
- func (e *Environment) Rename(ctx context.Context, from, to string) error
- func (e *Environment) Run(ctx context.Context, script, dir string, env map[string]string, ...) (int, error)
- func (e *Environment) Stat(ctx context.Context, name string, follow bool) (fs.FileInfo, error)
- func (e *Environment) Truncate(ctx context.Context, name string, size int64) error
- func (e *Environment) Write(ctx context.Context, name string, content []byte, appending bool) error
- type Mount
- type Python
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Computer ¶
type Computer struct {
// contains filtered or unexported fields
}
A Computer is one agent's computer. Its methods are safe for concurrent use.
func (*Computer) About ¶
About is what an agent is told about this computer, given the commands that call tools and their modules in Python, as ToolCommands and ToolModules name them.
func (*Computer) Close ¶
Close removes what the computer keeps on the host. The caller's mounts are the caller's and stay.
func (*Computer) Describe ¶
Describe is what a model is told about this computer, with the commands that call tools as they are now.
func (*Computer) Environment ¶
func (c *Computer) Environment() *Environment
Environment is the computer as an Environment. Every method may be called from any goroutine.
func (*Computer) Exec ¶
func (c *Computer) Exec(ctx context.Context, req *gbash.ExecutionRequest) (*gbash.ExecutionResult, error)
Exec runs a script or a command in the computer's shell, with the tools as they are now. A request with no Env starts where the last one ended: gbash keeps files between requests, and Exec carries the working directory and the exported variables.
func (*Computer) MCPServer ¶
MCPServer is the computer as an MCP server for an agent, with the tools bash, read, edit and write. The caller connects it: server.Run(ctx, &mcp.StdioTransport{}) for an agent that starts the computer as a program, or server.Connect with one end of mcp.NewInMemoryTransports for an agent in this process. limit is how long a bash call may run when the agent sets no shorter time. The file tools and their wording are gbash's codingtools' read, edit and write.
A computer is one agent's: every server made from it shares the one shell, with its working directory and variables. The file tools take a relative path from the computer's WorkDir, wherever the shell has since moved. The bash tool describes the commands that call tools as they are when MCPServer is called.
func (*Computer) Options ¶
Options is the computer as gbash options, with the tools as they are now, for gbash's own front ends: its command-line program, its server and its tool for a model.
func (*Computer) Session ¶
Session is the computer's shell session, for its filesystem and for interactive use. The tools are listed on every call: when they have changed, the commands and the Python package are made again and the session is a new one over the same files.
func (*Computer) ToolCommands ¶
ToolCommands are the commands that call tools, as the shell last built names them.
func (*Computer) ToolModules ¶
ToolModules are the modules of the Python package tools, one per command of ToolCommands, in its order.
type Config ¶
type Config struct {
Mounts []Mount
WorkDir string // where a command starts; a mount, or a directory in one
Commands []commands.Command // commands beyond the shell's own
Tools []tools.Source // the MCP servers whose tools become commands and the Python package `tools`
Python *Python // python3; nil for none
// Options are further gbash options, applied last: gbash.WithHTTPAccess or WithNetwork for curl, which the
// computer otherwise lacks, WithLimitOverrides, WithTracing, WithPolicy.
Options []gbash.Option
}
Config is what one computer is made of. Only Mounts is needed for a working shell.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
An Environment is the computer as the place an agent harness's own tools act: shell commands, and files, under the rules the shell's commands are held to. Its methods use only the standard library's types, so a harness can declare the interface it needs and be given this without either importing the other.
A name is an absolute path in the computer. An error is a *fs.PathError naming that path and never the host's, and errors.Is tells fs.ErrNotExist, fs.ErrPermission (also a write the rules refuse), fs.ErrExist, fs.ErrInvalid (also a file past the size limit), syscall.ENOTDIR, syscall.EISDIR and syscall.ENOTEMPTY apart. Which of them a misuse gets is the mount's to say: a host directory answers as a file system does, and a mount that is another afero.Fs as that one does: afero's memory filesystem allows a file made under a file, which turns that file into a directory and loses what it held.
func (*Environment) Mkdir ¶
Mkdir makes a directory, and with parents every directory above it that is missing; with parents, one that is there already is no error.
func (*Environment) Read ¶
Read reads length bytes of a file from offset, or as many as it has; the rest of it when length is negative.
func (*Environment) Remove ¶
Remove removes a file or an empty directory, or with recursive a directory and everything in it. Nothing there to remove is fs.ErrNotExist.
func (*Environment) Rename ¶
func (e *Environment) Rename(ctx context.Context, from, to string) error
Rename moves a file or a directory.
func (*Environment) Run ¶
func (e *Environment) Run(ctx context.Context, script, dir string, env map[string]string, replaceEnv bool, stdout, stderr io.Writer) (int, error)
Run runs script in the computer's shell with dir as its working directory, and returns its exit code. env is added to the shell's environment, or is the whole of it when replaceEnv is set. Each Run has a shell of its own over the computer's files: nothing is carried from one to the next, and one neither waits for another nor for the computer's own Exec. Output is written to stdout and stderr while the command runs, and a pipeline's commands may write at the same time. When ctx ends the command is stopped and ctx's error returned. A command that ran and failed, or that the shell does not have (127), is an exit code and no error.
type Mount ¶
A Mount is a directory the shell and every program see at the path Guest: the filesystem FS, which can be anything that implements afero.Fs, or, when FS is nil, the host directory Host (see files.Dir).
type Python ¶
type Python struct {
// contains filtered or unexported fields
}
Python is a wasi-python, compiled once and shared by every computer of the process.
func EmbeddedPython ¶
EmbeddedPython compiles the wasi-python release this module carries: CPython with numpy, pandas, scipy, scikit-learn, statsmodels, matplotlib, Pillow, lxml, python-docx, python-pptx and more. On first use it unpacks the release, about 270 MB, into computer/python-<checksum> in the user's cache directory (os.UserCacheDir), and later processes reuse it; a host must not mount that directory. Each call compiles the program again, so a host calls it once and shares the Python, as with LoadPython.
func LoadPython ¶
LoadPython reads the wasi-python release unpacked in dir, laid out as EmbeddedPython unpacks it: python.wasm, lib/python315.zip (alone in lib) and mpl-data/, matplotlib's data, and starts compiling it; the first python3 waits for the compile, and fails with its error. p's Binary is read from the file, its host call is answered by the computer's tools, and a zero MemoryPages is 8192 (512 MiB); its other fields are the caller's.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
computer
command
Command computer runs a sandboxed computer from the command line.
|
Command computer runs a sandboxed computer from the command line. |
|
Package extra holds the PDF commands the shell lacks, pdftotext and pdftoppm.
|
Package extra holds the PDF commands the shell lacks, pdftotext and pdftoppm. |
|
Package files has the filesystems a computer can be given.
|
Package files has the filesystems a computer can be given. |
|
Package tools turns the tools of an MCP server into what a shell and a script can use: a command per group of tools, with a subcommand per tool, and a Python package with a module per group and a function per tool.
|
Package tools turns the tools of an MCP server into what a shell and a script can use: a command per group of tools, with a subcommand per tool, and a Python package with a module per group and a function per tool. |
|
Package wasm runs a WebAssembly program built for WASI the way a command runs: with arguments, an environment, standard streams and directories, to an exit code.
|
Package wasm runs a WebAssembly program built for WASI the way a command runs: with arguments, an environment, standard streams and directories, to an exit code. |