Experimental_SandboxSession
The Experimental_SandboxSession interface describes an execution environment that
tools can use to run commands and access files. Pass an experimental sandbox using the
experimental_sandbox option to generateText, streamText,
ToolLoopAgent.generate, ToolLoopAgent.stream, or agent UI stream helpers to
make it available to tool description functions and tool execution.
This API is experimental and can change in patch releases. Passing an experimental sandbox does not sandbox the tool itself. Tool code still runs in your application process unless the tool explicitly delegates work to the experimental sandbox.
Import
import type { Experimental_SandboxSession } from "ai"
Type Definition
Paths
Relative paths in every method, including the workingDirectory option of run
and spawn, resolve against the same base directory: the directory that run
and spawn start in when no workingDirectory is given. The base directory does
not change for the lifetime of the session. Changing the directory inside a
command, for example with cd, only affects that command. Absolute paths are
used as is.
This lets tools combine methods. For example, a path that a grep command run
with run prints can be passed to readTextFile.
Properties
stdin: true, standard input stays open and the handle also has a writable stdin stream; implementations that do not support this reject before starting the command.null when the file does not exist. readTextFile accepts an encoding (default utf-8) and 1-based inclusive startLine and endLine.file, directory, or other) and size in bytes of a path. The size of a directory is implementation-defined. Symbolic links are followed. Resolves to null when the path does not exist.name and a type (file, directory, symlink, or other); symbolic links are not followed. The order is unspecified. Resolves to null when the directory does not exist and rejects when the path is not a directory.true when the file was deleted and false when it does not exist. Rejects when the path is a directory.Example
Inside a tool, read the experimental sandbox from the second execute argument: