Skip to content

fix(deno): transfer sandbox files as bytes instead of UTF-8 text - #986

Open
Mihir Inamdar (inamdarmihir) wants to merge 1 commit into
langchain-ai:mainfrom
inamdarmihir:fix/deno-sandbox-binary-transfer
Open

Mihir Inamdar (inamdarmihir) wants to merge 1 commit into
langchain-ai:mainfrom
inamdarmihir:fix/deno-sandbox-binary-transfer

Conversation

@inamdarmihir

Copy link
Copy Markdown

Fixes #888.

Problem

DenoSandbox.uploadFiles decoded each Uint8Array to a string and wrote it with fs.writeTextFile. downloadFiles re-encoded the stdoutText view of cat. Any byte sequence that isn't valid UTF-8 was replaced with U+FFFD, and the call still reported success, so images, PDFs and archives moved through the sandbox came back corrupted.

Change

  • uploadFiles writes the bytes with fs.writeFile.
  • downloadFiles returns the raw stdout bytes instead of re-encoding stdoutText.
  • Added a patch changeset for @langchain/deno.

The cat approach and its error mapping (file_not_found and so on) are unchanged.

Tests

  • The mock sandbox in sandbox.test.ts now stores files as bytes and exposes the SDK's fs.writeFile, with a lossy stdoutText view like the real SDK. The old mock kept strings, so it couldn't tell the two paths apart.
  • New tests: a non-UTF-8 byte sequence survives upload, and survives download, byte for byte. All three byte-level tests fail on the old implementation and pass now.
  • oxfmt --check and oxlint are clean, and tsc reports no errors in sandbox.ts.

libs/providers/deno unit tests: 57 pass, 3 fail. The 3 failures (should create sandbox via SDK, should work with default options, should pass options to sandbox creation, all memoryMb undefined) also fail on an unmodified main; this change doesn't touch them. Six tests failed before my change, because the mock exposed writeTextFile on the sandbox while the code calls sandbox.fs.writeTextFile. Updating the mock for the upload path fixed the three upload tests.

I did not run the integration tests, which need a Deno Deploy account, so this hasn't been verified against a real sandbox.

Authored by Mihir

uploadFiles decoded the Uint8Array to a string and wrote it with
writeTextFile, and downloadFiles re-encoded the text view of stdout.
Any byte sequence that is not valid UTF-8 was replaced with U+FFFD while
the call reported success, so images, PDFs and archives came back
corrupted.

Write with fs.writeFile and return the raw stdout bytes. The mock
sandbox now keeps files as bytes and exposes fs.writeFile, so the tests
can tell the two apart; the new tests fail on the old implementation.

Fixes langchain-ai#888

Authored by Mihir
@changeset-bot

changeset-bot Bot commented Oct 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c7b28d9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@langchain/deno Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

Mihir Inamdar (@inamdarmihir) is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Oct 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

deepagents-acp

npm i https://pkg.pr.new/deepagents-acp@986

deepagents

npm i https://pkg.pr.new/deepagents@986

@langchain/sandbox-standard-tests

npm i https://pkg.pr.new/@langchain/sandbox-standard-tests@986

@langchain/daytona

npm i https://pkg.pr.new/@langchain/daytona@986

@langchain/deno

npm i https://pkg.pr.new/@langchain/deno@986

@langchain/modal

npm i https://pkg.pr.new/@langchain/modal@986

@langchain/node-vfs

npm i https://pkg.pr.new/@langchain/node-vfs@986

@langchain/quickjs

npm i https://pkg.pr.new/@langchain/quickjs@986

commit: c7b28d9

This branch has not been deployed

No deployments
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.

DenoSandbox file transfers corrupt binary bytes through UTF-8 conversion

1 participant