[PR #322] [MERGED] feat(node-vfs): enhance VfsSandbox to support absolute paths execute #357

Closed
opened 2026-06-05 17:22:47 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/322
Author: @hnustwjj
Created: 3/17/2026
Status: Merged
Merged: 3/20/2026
Merged by: @christian-bromann

Base: mainHead: fix_vfs


📝 Commits (4)

  • 20a7f17 feat(node-vfs): enhance VfsSandbox to support absolute paths in commands and add related integration tests
  • 675250b fix(node-vfs): add changeset for rewriting absolute VFS paths in execute() commands
  • d4a87b2 Merge branch 'main' into fix_vfs
  • 343f0f4 fix: ci

📊 Changes

3 files changed (+101 additions, -5 deletions)

View changed files

.changeset/fix-vfs-absolute-paths.md (+5 -0)
📝 libs/providers/node-vfs/src/sandbox.int.test.ts (+51 -3)
📝 libs/providers/node-vfs/src/sandbox.ts (+45 -2)

📄 Description

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/322 **Author:** [@hnustwjj](https://github.com/hnustwjj) **Created:** 3/17/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@christian-bromann](https://github.com/christian-bromann) **Base:** `main` ← **Head:** `fix_vfs` --- ### 📝 Commits (4) - [`20a7f17`](https://github.com/langchain-ai/deepagentsjs/commit/20a7f17fe009add28c3c258cc3a82da4a37c7cd0) feat(node-vfs): enhance VfsSandbox to support absolute paths in commands and add related integration tests - [`675250b`](https://github.com/langchain-ai/deepagentsjs/commit/675250b73f8a39ae3aad8cc017d34e6ae11c7b38) fix(node-vfs): add changeset for rewriting absolute VFS paths in execute() commands - [`d4a87b2`](https://github.com/langchain-ai/deepagentsjs/commit/d4a87b22f04b14137a9283627fefe1f064c93498) Merge branch 'main' into fix_vfs - [`343f0f4`](https://github.com/langchain-ai/deepagentsjs/commit/343f0f46221f9e2d185c365c1c4f9e2d50834942) fix: ci ### 📊 Changes **3 files changed** (+101 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/fix-vfs-absolute-paths.md` (+5 -0) 📝 `libs/providers/node-vfs/src/sandbox.int.test.ts` (+51 -3) 📝 `libs/providers/node-vfs/src/sandbox.ts` (+45 -2) </details> ### 📄 Description # 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: ```typescript 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 - [x] New test: `should run a multi-file Node.js project with absolute paths` — verifies `node /src/index.js` with cross-file `require()` - [x] New test: `should access initialFiles with leading slash via execute() using absolute path` — verifies single-file absolute path execution - [x] New test: `should run a multi-file Node.js project with absolute paths from README (absolute execute)` — mirrors README example with absolute path - [x] All 28 unit tests pass - [x] All 125 integration tests pass (including 92 standard tests) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:22:47 -04:00
yindo closed this issue 2026-06-05 17:22:47 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#357