feat: sandbox shell execution abstraction#14949
Merged
Merged
Conversation
gr2m
reviewed
May 5, 2026
nicoalbanese
reviewed
May 6, 2026
nicoalbanese
approved these changes
May 7, 2026
1 task
lgrammel
added a commit
that referenced
this pull request
May 7, 2026
) ## Background We introduced a sandbox abstraction in #14949 When possible, provider defined tools should automatically leverage it unless the users provide custom execution functions. ## Summary Automatically use sandbox by default in Anthropic bash tools. ## Example ```ts const result = await generateText({ model: anthropic('claude-opus-4-7'), tools: { bash: anthropic.tools.bash_20250124(), }, sandbox: new LocalSandbox({ rootDirectory: `${process.env.HOME}/Downloads`, }), stopWhen: isStepCount(2), prompt: 'List the files in my home directory.', }); ``` ## Manual Verification - [x] run and verify `examples/ai-functions/src/generate-text/anthropic/bash-tool.ts` ## Future Work - sandbox type safety - apply to bash tools from other providers ## Related Issues Builds upon #14949
This was referenced May 8, 2026
5 tasks
felixarntz
added a commit
that referenced
this pull request
May 18, 2026
… wrappers to `Experimental_Sandbox` abstraction (#15345) ## Background `Experimental_Sandbox` (previous: #14949, #15253, #15301) only exposed `description` and `runCommand`, so tools that needed file I/O had to wrap every read/write in a shell command (`cat`, `tee`, `echo > …`). That is fragile for binary content and impossible to type properly. ## Summary - Adds six file methods to `Experimental_Sandbox`: streaming `readFile`/`writeFile` as the foundation, plus `readBinaryFile`/`readTextFile` and `writeBinaryFile`/`writeTextFile` as convenience wrappers. - All methods take a single options object so additional fields can be added without breaking the signature. - Using a stream for the foundation is the most low-level and future-proof primitive, plus it handles large files better. - In a follow up PR, we'll add another reduced abstraction surface, because technically a sandbox provider shouldn't have to implement the convenience wrappers `readTextFile`, `writeTextFile`, etc. This can take inspiration from (or continue with) #15311. - Updates the three example sandbox implementations (`LocalSandbox`, `JustBashSandbox`, both `VercelSandbox` copies) to implement the new methods, using streaming `readFile`/`writeFile` as the foundation that the binary and text variants delegate to. ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [x] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Future Work See above: We'll need to add that reduced abstraction surface so that only essential methods _have_ to be implemented by the provider. We can provide a helper function to fill in the convenience wrappers automatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Many agents are using filesystems through shell and file read/write tools, often in separate sandbox environments. These agents are so common that a first-class sandbox abstraction would be beneficial.
Summary
Sandboxtypesandboxoption togenerateText,streamText,ToolLoopAgentToolExecutionOptionsExample
Tool definition:
Agent definition:
Agent call:
Manual Verification
src/agent/openai/generate-local-sandboxsrc/agent/openai/stream-local-sandboxexamples/ai-e2e-next/app/chat/sandbox/page.tsxFuture Work