Skip to content

fix: add --sandbox-shared-modules flag - #9163

Closed
sid-bruno wants to merge 3 commits into
usebruno:mainfrom
sid-bruno:feat/cli-shared-modules-cache-flag
Closed

fix: add --sandbox-shared-modules flag#9163
sid-bruno wants to merge 3 commits into
usebruno:mainfrom
sid-bruno:feat/cli-shared-modules-cache-flag

Conversation

@sid-bruno

Copy link
Copy Markdown
Collaborator

Description

TBD

Problem

Fix

Screenshots

Before After

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.
  • I've run the claude code review skill locally.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The shared require path introduces behavior gaps (notably path separator normalization and bypassed allowlist semantics) that can break cross-platform scripts and weaken existing sandbox path validation expectations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an opt-in CLI flag to enable shared CommonJS module instances across Node VM script executions (via Node’s require.cache) to support stateful module reuse within a single bru run invocation.

Changes:

  • Introduces createSharedRequire() and wires scriptingConfig.sharedModules into the Node VM sandbox.
  • Adds --sandbox-shared-modules flag plumbing in the CLI (run command → runner → scripting config).
  • Adds unit tests (bruno-js) and an integration test (bruno-cli) validating shared vs isolated module behavior and resolution fallbacks.
File summaries
File Description
packages/bruno-js/src/sandbox/node-vm/index.js Switches require implementation based on scriptingConfig.sharedModules.
packages/bruno-js/src/sandbox/node-vm/cjs-loader.js Adds createSharedRequire() that resolves modules relative to the collection and falls back to Bruno-bundled modules.
packages/bruno-js/src/sandbox/node-vm/index.spec.js Adds unit coverage for shared module instance behavior and resolution rules.
packages/bruno-cli/src/commands/run.js Adds --sandbox-shared-modules option and maps it into internal runner options.
packages/bruno-cli/src/runner/run-single-request.js Passes CLI option into scriptingConfig.sharedModules.
packages/bruno-cli/tests/integration/run-sandbox-shared-modules.spec.js New integration suite validating module sharing across requests and safe-sandbox compatibility.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +57 to +69
// Shared host require (opt-in) or per-script custom CJS loader
if (get(scriptingConfig, 'sharedModules')) {
scriptContext.require = createSharedRequire(collectionPath);
} else {
const localModuleCache = new Map();
scriptContext.require = createCustomRequire({
collectionPath,
isolatedContext,
currentModuleDir: collectionPath,
localModuleCache,
additionalContextRootsAbsolute
});
}
Comment on lines +18 to +25
beforeAll(async () => {
server = http.createServer((_req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('ok');
});
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
port = server.address().port;
});
Comment on lines +391 to +411
return (moduleName) => {
if (isBuiltinModule(moduleName)) {
return require(moduleName);
}

let resolvedPath;
try {
resolvedPath = collectionRequire.resolve(moduleName);
} catch {
try {
resolvedPath = require.resolve(moduleName, { paths: module.paths });
} catch (mainError) {
throw new Error(
`Could not resolve module "${moduleName}": ${mainError.message}\n\n`
+ `Install it with: npm install ${moduleName}`
);
}
}

return require(resolvedPath);
};
@pull-request-size pull-request-size Bot added size/XL and removed size/L labels Sep 3, 2026
@sid-bruno sid-bruno changed the title fix: add --sandbox-shared-moduels flag fix: add --sandbox-shared-modules flag Sep 3, 2026
@sid-bruno

Copy link
Copy Markdown
Collaborator Author

Closed for #9170

@sid-bruno sid-bruno closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants