Skip to content

feat(sandbox): accept string and Uint8Array in writeFiles content#128

Merged
marc-vercel merged 2 commits into
mainfrom
nr/write-files-string-content
Apr 2, 2026
Merged

feat(sandbox): accept string and Uint8Array in writeFiles content#128
marc-vercel merged 2 commits into
mainfrom
nr/write-files-string-content

Conversation

@TooTallNate
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate commented Apr 1, 2026

Summary

  • Widens the writeFiles() content type from Buffer to string | Uint8Array (Buffer is implied since it extends Uint8Array)
  • This allows passing strings directly without needing Buffer.from(), which is important for environments where Buffer is not available (e.g. workflow runtime contexts)
  • Renames the internal FileBuffer interface to FileData to reflect the widened type
  • Adds tests for string and Uint8Array content in FileWriter
  • Fixes all FileWriter tests to properly await the writer.end() promise

Copilot AI review requested due to automatic review settings April 1, 2026 23:55
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sandbox Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 8:23am
sandbox-cli Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 8:23am
sandbox-sdk Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 8:23am
sandbox-sdk-ai-example Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 8:23am
workflow-code-runner Ready Ready Preview, Comment, Open in v0 Apr 2, 2026 8:23am

Request Review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR widens the public writeFiles() API (and underlying tar/gzip FileWriter) to accept string | Uint8Array content, reducing reliance on Node’s Buffer type in consumer code and adding coverage for the new input forms.

Changes:

  • Update Sandbox.writeFiles() and APIClient.writeFiles() param types to string | Uint8Array.
  • Update FileWriter file content typing accordingly.
  • Add FileWriter tests for string and Uint8Array (including multi-byte UTF-8) and add a changeset entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/vercel-sandbox/src/sandbox.ts Widens Sandbox.writeFiles() file content type and updates example usage.
packages/vercel-sandbox/src/api-client/api-client.ts Widens APIClient.writeFiles() parameter typing to match the new public API.
packages/vercel-sandbox/src/api-client/file-writer.ts Updates FileWriter’s buffered file content type to `string
packages/vercel-sandbox/src/api-client/file-writer.test.ts Adds test coverage for string and Uint8Array content handling.
.changeset/write-files-string-content.md Records the patch change for release notes/versioning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/vercel-sandbox/src/api-client/file-writer.ts
Comment thread packages/vercel-sandbox/src/api-client/file-writer.test.ts Outdated
Copy link
Copy Markdown
Collaborator

@marc-vercel marc-vercel left a comment

Choose a reason for hiding this comment

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

LGTM, the Copilot comment https://github.com/vercel/sandbox/pull/128/changes#r3025225916 might be valid.

Do we also plan, in the future, to support readFileToString (in the same way we have readFileToBuffer), if we are supporting strings with write? Not a requirement, just wondering.

@TooTallNate
Copy link
Copy Markdown
Member Author

Do we also plan, in the future, to support readFileToString (in the same way we have readFileToBuffer), if we are supporting strings with write? Not a requirement, just wondering.

Not sure tbh. My personal preference would be to remove any Node.js-specific APIs from this package entirely. That is, there should be a readFile() function that returns Uint8Array only. If you want a string, use TextDecoder. Deprecate readFileToBuffer(). But that's not my call 😄

Comment thread packages/vercel-sandbox/src/api-client/file-writer.ts
@marc-vercel marc-vercel merged commit 451c42e into main Apr 2, 2026
14 checks passed
@marc-vercel marc-vercel deleted the nr/write-files-string-content branch April 2, 2026 09:16
@github-actions github-actions Bot mentioned this pull request Apr 1, 2026
marc-vercel added a commit that referenced this pull request Apr 2, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## sandbox@2.5.7

### Patch Changes

- Updated dependencies
\[[`cf13a34221c2b83c25c73d94929d05e0a697aecf`](cf13a34),
[`772989c59a3c27efa98153cdc54b6e35c1c15eae`](772989c),
[`184cd42d8d3b1ea1df354529cb6ba103a33e18d3`](184cd42),
[`451c42efb94ab9c9dc330b4742071ac01008044d`](451c42e)]:
    -   @vercel/sandbox@1.9.1

## @vercel/sandbox@1.9.1

### Patch Changes

- Build and publish both ESM and CJS outputs for the SDK package.
([#84](#84))

- Support useworkflow serialization for sandboxes and commands
([#72](#72))

- Fix a Size mismatch when encoding binaries during write operations
([#127](#127))

- Accept `string` and `Uint8Array` in `writeFiles()` content, not just
`Buffer`. ([#128](#128))

## sandbox-filesystem-snapshots@0.0.12

### Patch Changes

- Updated dependencies
\[[`cf13a34221c2b83c25c73d94929d05e0a697aecf`](cf13a34),
[`772989c59a3c27efa98153cdc54b6e35c1c15eae`](772989c),
[`184cd42d8d3b1ea1df354529cb6ba103a33e18d3`](184cd42),
[`451c42efb94ab9c9dc330b4742071ac01008044d`](451c42e)]:
    -   @vercel/sandbox@1.9.1

## workflow-code-runner@0.1.1

### Patch Changes

- Updated dependencies
\[[`cf13a34221c2b83c25c73d94929d05e0a697aecf`](cf13a34),
[`772989c59a3c27efa98153cdc54b6e35c1c15eae`](772989c),
[`184cd42d8d3b1ea1df354529cb6ba103a33e18d3`](184cd42),
[`451c42efb94ab9c9dc330b4742071ac01008044d`](451c42e)]:
    -   @vercel/sandbox@1.9.1

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marc Codina <marc.codina@vercel.com>
marc-vercel pushed a commit that referenced this pull request Apr 8, 2026
## Summary

- Widens the `writeFiles()` `content` type from `Buffer` to `string |
Uint8Array` (`Buffer` is implied since it extends `Uint8Array`)
- This allows passing strings directly without needing `Buffer.from()`,
which is important for environments where `Buffer` is not available
(e.g. workflow runtime contexts)
- Renames the internal `FileBuffer` interface to `FileData` to reflect
the widened type
- Adds tests for string and Uint8Array content in `FileWriter`
- Fixes all `FileWriter` tests to properly `await` the `writer.end()`
promise
marc-vercel added a commit that referenced this pull request Apr 8, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.

- Updated dependencies
\[[`cf13a34221c2b83c25c73d94929d05e0a697aecf`](cf13a34),
[`772989c59a3c27efa98153cdc54b6e35c1c15eae`](772989c),
[`184cd42d8d3b1ea1df354529cb6ba103a33e18d3`](184cd42),
[`451c42efb94ab9c9dc330b4742071ac01008044d`](451c42e)]:
    -   @vercel/sandbox@1.9.1

- Build and publish both ESM and CJS outputs for the SDK package.
([#84](#84))

- Support useworkflow serialization for sandboxes and commands
([#72](#72))

- Fix a Size mismatch when encoding binaries during write operations
([#127](#127))

- Accept `string` and `Uint8Array` in `writeFiles()` content, not just
`Buffer`. ([#128](#128))

- Updated dependencies
\[[`cf13a34221c2b83c25c73d94929d05e0a697aecf`](cf13a34),
[`772989c59a3c27efa98153cdc54b6e35c1c15eae`](772989c),
[`184cd42d8d3b1ea1df354529cb6ba103a33e18d3`](184cd42),
[`451c42efb94ab9c9dc330b4742071ac01008044d`](451c42e)]:
    -   @vercel/sandbox@1.9.1

- Updated dependencies
\[[`cf13a34221c2b83c25c73d94929d05e0a697aecf`](cf13a34),
[`772989c59a3c27efa98153cdc54b6e35c1c15eae`](772989c),
[`184cd42d8d3b1ea1df354529cb6ba103a33e18d3`](184cd42),
[`451c42efb94ab9c9dc330b4742071ac01008044d`](451c42e)]:
    -   @vercel/sandbox@1.9.1

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marc Codina <marc.codina@vercel.com>
marc-vercel added a commit that referenced this pull request Apr 8, 2026
Rebasing `named-sandboxes`. Commits that I am moving:

1. cf13a34 — refactor(sdk): build @vercel/sandbox with tsdown dual
outputs (#84)
2. 772989c — Support "use workflow" serialization for Sandbox and
Command (#72)
3. cc74dbf — fix(sandbox): read package.json with fs instead of ESM
import (#119)
4. a6b8ce9 — feat(skill): update beta documentation for default snapshot
expiration (#125)
5. 184cd42 — patch(vercel-sandbox): count length by bytes and not ASCII
for binaries (#127)
6. 451c42e — feat(sandbox): accept string and Uint8Array in writeFiles
content (#128)
7. ad52dec — Version Packages (#122)
8. b91b9e4 — fix(sandbox): initialize API client in Command before
reading output (#130)
9. 28237b8 — refactor(workflow-code-runner): inline Sandbox calls in
workflow function (#129)
10. 0786e18 — Version Packages (#131)
11. 9555162 — fix(sandbox): handle abort signal and early stream close
in runCommand (#135)
12. db4e5f3 — Version Packages (#137)

I had to resolve multiple merge conflicts, specially with the commits 1
and 2. I've also added some tests for them because they were touching
`sandbox.ts` for serializing and deserializing, and in this branch we
moved most of the logic to `session.ts`.

---------

Co-authored-by: Gal Schlezinger <gal@spitfire.co.il>
Co-authored-by: Luke Phillips-Sheard <luke.phillips-sheard@vercel.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Luke PS <LukeSheard@users.noreply.github.com>
Co-authored-by: Malte Ubl <cramforce@users.noreply.github.com>
Co-authored-by: Pranay Prakash <pranay.gp@gmail.com>
Co-authored-by: Nathan Rajlich <n@n8.io>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Phil Z <pbzona@users.noreply.github.com>
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.

5 participants