Skip to content

feat(node-vfs): enhance VfsSandbox to support absolute paths execute#322

Merged
Christian Bromann (christian-bromann) merged 4 commits intolangchain-ai:mainfrom
hnustwjj:fix_vfs
Mar 20, 2026
Merged

feat(node-vfs): enhance VfsSandbox to support absolute paths execute#322
Christian Bromann (christian-bromann) merged 4 commits intolangchain-ai:mainfrom
hnustwjj:fix_vfs

Conversation

@hnustwjj
Copy link
Copy Markdown
Contributor

fix(node-vfs): rewrite absolute VFS paths in execute() commands

Summary

  • Fix VfsSandbox.execute() to support absolute paths (e.g. node /src/index.js) by rewriting them to the temp directory path before shell execution
  • Add integration tests covering absolute path command execution for single-file and multi-file Node.js projects

Problem

When users define initialFiles with absolute paths like /src/index.js, the VFS correctly stores and syncs files to a temp directory for execution. However, commands referencing those files with absolute paths fail:

const sandbox = await VfsSandbox.create({
  initialFiles: { "/src/index.js": "console.log('Hello')" },
});

await sandbox.execute("node src/index.js");   // ✅ works (relative → resolves via cwd)
await sandbox.execute("node /src/index.js");  // ❌ fails (absolute → resolves against host root)

The #normalizeExecPath method already handles leading / for read(), ls(), grep(), glob(), but execute() passes the raw command string directly to /bin/bash -c without any path translation.

Solution

Add a #rewriteVfsPaths(command, execDir) private method that:

  1. Reads the top-level entry names from the VFS workspace (e.g. src, data.json)
  2. For each entry, uses a regex to match /<name> at path-token boundaries in the command
  3. Replaces matched absolute paths with <tempDir>/<name>

The regex uses negative lookbehind ((?<![\w/.-])) and positive lookahead ((?=/|[\s"';|&><!]|$)) to ensure only standalone absolute path tokens are rewritten, leaving system paths like /bin/bash or /usr/local/bin/node untouched (since bin, usr are not VFS entries).

Test plan

  • New test: should run a multi-file Node.js project with absolute paths — verifies node /src/index.js with cross-file require()
  • New test: should access initialFiles with leading slash via execute() using absolute path — verifies single-file absolute path execution
  • New test: should run a multi-file Node.js project with absolute paths from README (absolute execute) — mirrors README example with absolute path
  • All 28 unit tests pass
  • All 125 integration tests pass (including 92 standard tests)

…nds and add related integration tests

- Implemented a method to rewrite absolute paths in commands referencing VFS entries to point to the temporary directory.
- Added integration tests for executing multi-file Node.js projects with both absolute and relative paths.
- Updated existing tests to clarify path usage in commands.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: 343f0f4

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

This PR includes changesets to release 1 package
Name Type
@langchain/node-vfs 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

@hnustwjj
Copy link
Copy Markdown
Contributor Author

Christian Bromann (@christian-bromann) Thank you for your feedback. I’ll fix the ci command first.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/deepagents-acp@322
npm i https://pkg.pr.new/deepagents@322
npm i https://pkg.pr.new/@langchain/sandbox-standard-tests@322

commit: 343f0f4

@christian-bromann Christian Bromann (christian-bromann) merged commit 8dc4e9c into langchain-ai:main Mar 20, 2026
12 checks passed
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
@hnustwjj
Copy link
Copy Markdown
Contributor Author

Christian Bromann (@christian-bromann) thank you for your approve. i'll be appreciate if you could help me to review another pr?

Colin Francis (colifran) pushed a commit that referenced this pull request Mar 24, 2026
…322)

* feat(node-vfs): enhance VfsSandbox to support absolute paths in commands and add related integration tests

- Implemented a method to rewrite absolute paths in commands referencing VFS entries to point to the temporary directory.
- Added integration tests for executing multi-file Node.js projects with both absolute and relative paths.
- Updated existing tests to clarify path usage in commands.

* fix(node-vfs): add changeset for rewriting absolute VFS paths in execute() commands

* fix: ci

---------

Co-authored-by: wangjiangjian.0224 <wangjiangjian.0224@bytedance.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.

2 participants