Skip to content

feat(provider-utils): add readFile and writeFile plus convenience wrappers to Experimental_Sandbox abstraction#15345

Merged
felixarntz merged 5 commits into
mainfrom
fa/sandbox-read-write
May 18, 2026
Merged

feat(provider-utils): add readFile and writeFile plus convenience wrappers to Experimental_Sandbox abstraction#15345
felixarntz merged 5 commits into
mainfrom
fa/sandbox-read-write

Conversation

@felixarntz
Copy link
Copy Markdown
Collaborator

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) provider sandbox #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

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • 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.

/**
* 1-based inclusive start line. Defaults to 1.
*/
startLine?: number;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we consider a linebreak? presumably \n but we may want an optional linebreak field that allows setting \r or \n or \r\n

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, though I think an option feels a bit too low-level. I implemented a helper in provider-utils instead for extracting lines which detects the line break format used in a file and maintains it.

If this shows to be problematic, we can still considering adding an option.

* No-op stubs for the file methods on `Experimental_Sandbox`, intended to be
* spread into test fixtures that only care about `runCommand`.
*/
export const mockSandboxFileStubs: Pick<
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if it's worth moving to provider-utils so providers can use this for testing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure about this. Do we have other test-only helpers in provider-utils? Either way, we could add this later if there's value.

@felixarntz felixarntz merged commit a6617c5 into main May 18, 2026
19 checks passed
@felixarntz felixarntz deleted the fa/sandbox-read-write branch May 18, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants