Skip to content

sandbox-just-bash: writes through a symlinked directory are lost, and deleteFile throws #25591

Todo

Description

@FredAmartey

Description

In a @ai-sdk/sandbox-just-bash session, changing a file through a symlinked directory doesn't work, while reading through the same link does:

  • writeTextFile and writeBinaryFile resolve without an error, but the file can't be read back, through the link or in the real directory.
  • deleteFile throws ENOENT: no such file or directory, rm '/work/link/old.txt', although stat on the same path finds the file.
  • A shell command such as echo hi > /work/link/a.txt exits 0 and writes nothing.

An agent that keeps its workspace behind a symlink, or creates one with ln -s, loses its writes without any error.

The cause is in just-bash's InMemoryFs: its write methods don't resolve symlinks in the parent path, while its read methods do. It's the same in just-bash 2.14.5, which this package depends on, and in the latest 3.6.1. I've opened a fix there: vercel-labs/just-bash#782.

Expected: writes, deletes and shell commands go to /work/real, as they do on a real filesystem.

Reproduction

// repro.mjs, after `npm install @ai-sdk/sandbox-just-bash@1.0.196`
import { createJustBashNetworkSandboxSession } from '@ai-sdk/sandbox-just-bash';

const session = (await createJustBashNetworkSandboxSession()).restricted();
await session.run({ command: 'mkdir -p /work/real && ln -s /work/real /work/link' });

await session.writeTextFile({ path: '/work/link/notes.md', content: 'hello' });
console.log('read back via link:', await session.readTextFile({ path: '/work/link/notes.md' }));
console.log('in the real dir:   ', await session.readTextFile({ path: '/work/real/notes.md' }));

await session.writeTextFile({ path: '/work/real/old.txt', content: 'x' });
try {
  console.log('deleteFile via link:', await session.deleteFile({ path: '/work/link/old.txt' }));
} catch (error) {
  console.log('deleteFile via link threw:', error.message);
}

const shell = await session.run({ command: 'echo hi > /work/link/a.txt; echo "exit $?"; ls /work/real' });
console.log('shell write via link:', JSON.stringify(shell.stdout));

node repro.mjs prints:

read back via link: null
in the real dir:    null
deleteFile via link threw: ENOENT: no such file or directory, rm '/work/link/old.txt'
shell write via link: "exit 0\nold.txt\n"

With the just-bash fix built from its main branch (3.6.1) and swapped in for the installed just-bash 2.14.5, the same script prints the expected output. Picking up the fix here means moving to a just-bash release that has it, since this package depends on ^2.14.5.

read back via link: hello
in the real dir:    hello
deleteFile via link: true
shell write via link: "exit 0\na.txt\nnotes.md\n"

AI SDK Version

  • @ai-sdk/sandbox-just-bash: 1.0.196 (just-bash 2.14.5)
  • ai: 7.0.184
  • Node 26.13.0, macOS

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. ai-sdk-factory commented on Nov 28, 2026

    @ai-sdk-factory
    Contributor

    Identify issue type

    Identified as Bug
    Confidence: High

    Rationale

    The issue reports concrete filesystem failures in current sandbox behavior: silently lost writes and unexpected deletion errors. The proposed dependency update addresses those failures rather than adding a new capability.

    Evidence

    • Writes through a symlinked directory report success but produce no readable file, including shell redirection that exits 0.
    • deleteFile throws ENOENT through a symlink even though stat finds the target file.
    • A reproduction demonstrates the failures, and an upstream just-bash fix reportedly restores expected behavior.
  2. ai-sdk-factory commented on Nov 28, 2026

    @ai-sdk-factory
    Contributor

    Bug discovery clarification

    @FredAmartey, how did you discover this bug? Did you encounter it while using the AI SDK in production, find it while auditing or reviewing AI SDK source code, or discover it another way? Please describe the original discovery context.

    The report demonstrates the bug and diagnoses an upstream cause, but does not establish whether it was originally discovered in production or through source auditing. Ask the original author how they discovered it.

  3. FredAmartey commented on Nov 29, 2026

    @FredAmartey
    Author

    Ran into this while using @ai-sdk/sandbox-just-bash in our staging env for a sandboxed agent workflow where a workspace path went through a symlinked directory.
    Reading files through the symlinked path worked normally, so it wasn't immediately obvious anything was wrong until we noticed writes were resolving/exiting 0 without persisting and deleteFile was throwing ENOENT on files stat could still see. From there I isolated the minimal reproduction above, traced the cause to just-bash's InMemoryFs, and opened vercel-labs/just-bash#782.

  4. ai-sdk-factory commented on Nov 29, 2026

    @ai-sdk-factory
    Contributor

    Identify bug discovery

    Discovery source: discovery:other (high confidence).

    The author explicitly discovered the bug in a staging environment, not production or a source audit. Source inspection occurred afterward to diagnose the failure.

    • The author clarified: “Ran into this while using @ai-sdk/sandbox-just-bash in our staging env for a sandboxed agent workflow.”
    • The workflow used a workspace path through a symlinked directory, where writes failed to persist and deleteFile threw ENOENT.
    • The author said they subsequently isolated the reproduction, traced the cause to InMemoryFs, and opened the upstream fix.
  5. FredAmartey commented on Nov 29, 2026

    @FredAmartey
    Author

    Bug discovery clarification

    @FredAmartey, how did you discover this bug? Did you encounter it while using the AI SDK in production, find it while auditing or reviewing AI SDK source code, or discover it another way? Please describe the original discovery context.

    The report demonstrates the bug and diagnoses an upstream cause, but does not establish whether it was originally discovered in production or through source auditing. Ask the original author how they discovered it.

    It is also present in our production environment

  6. ai-sdk-factory commented on Nov 30, 2026

    @ai-sdk-factory
    Contributor

    Bug Reproduction - AI SDK 7

    Bug is outside the AI SDK codebase scope.

    Target branch: main

    • Confirmed on target-branch @ai-sdk/sandbox-just-bash 1.0.197 with locked just-bash 2.14.5 under Node 22.23.4.
    • Reading and stat through /work/link succeed, but text and binary writes resolve without producing readable files through either path.
    • Deletion through /work/link/old.txt throws ENOENT and leaves the target intact; shell redirection exits 0 without persisting its output.
    • examples/ai-functions/src/reproduction/issue-25591.ts exercises every reported operation and fails because writes should persist in /work/real and deletion should remove the target.
    • Direct native just-bash operations exhibit identical failures. packages/sandbox-just-bash/src/just-bash-sandbox-session.ts forwards writes to fs.writeFile, deletion to fs.rm, and commands to native execution, locating the defect in external just-bash rather than SDK request shaping.
    • The reported just-bash 3.6.1 behavior and proposed upstream fix were not independently verified; no dependencies or production code were changed.

    Relevant Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions