sandbox-npm-install
它能做什么
这个工具会在你电脑上的隔离环境(沙箱)中安装 Node.js 软件包(即 npm packages)。它解决了一个常见问题:为特定机器(如 ARM 架构)编译的程序,在以特定方式(virtiofs)访问文件时无法正常工作。该工具会把这些软件包安装到一个安全的位置,并将其“链接”到你的项目中,使其正常运行。
适用场景
- ✓开始一个新的 Node.js 项目,第一次需要下载依赖项时。
- ✓修改了所需软件包列表(package.json 文件),需要更新安装时。
- ✓运行或构建项目时遇到奇怪的错误,尤其是与“原生二进制文件”有关的错误时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/sandbox-npm-install/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“在沙箱中为我的 Node.js 项目安装软件包。”
每周 5 个新技能,1 分钟读完。
工作原理
这个工具会把项目的配置文件复制到隔离环境内的一个安全区域。然后,它在那里运行安装命令(npm ci)。最后,它会创建一个快捷方式(符号链接),让你的项目能够安全地访问这些已安装的软件包。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Sandbox npm Install
When to Use This Skill
Use this skill whenever:
- You need to install npm packages for the first time in a new sandbox session
package.jsonorpackage-lock.jsonhas changed and you need to reinstall- You encounter native binary crashes with errors like
SIGILL,SIGSEGV,mmap, orunaligned sysNoHugePageOS - The
node_modulesdirectory is missing or corrupted
Prerequisites
- A Docker sandbox environment with a virtiofs-mounted workspace
- Node.js and npm available in the container
- A
package.jsonfile in the target workspace
Background
Docker sandbox workspaces are typically mounted via virtiofs (file sync between the host and Linux VM). Native Go and Rust binaries (esbuild, lightningcss, rollup, etc.) crash with mmap alignment failures when executed from virtiofs on aarch64. The fix is to install on the container's local ext4 filesystem and symlink back into the workspace.
Step-by-Step Installation
Run the bundled install script from the workspace root:
bash scripts/install.sh
Common Options
| Option | Description |
|---|---|
--workspace <path> |
Path to directory containing package.json (auto-detected if omitted) |
--playwright |
Also install Playwright Chromium browser for E2E testing |
What the Script Does
- Copies
package.json,package-lock.json, and.npmrc(if present) to a local ext4 directory - Runs
npm ci(ornpm installif no lockfile) on the local filesystem - Symlinks
node_modulesback into the workspace - Verifies known native binaries (esbuild, rollup, lightningcss, vite) if present
- Optionally installs Playwright browsers and system dependencies (uses
sudowhen available)
If verification fails, run the script again — crashes can be intermittent during initial setup.
Post-Install Verification
After the script completes, verify your toolchain works. For example:
npm test # Run project tests
npm run build # Build the project
npm run dev # Start dev server
Important Notes
- The local install directory (e.g.,
/home/agent/project-deps) is container-local and is NOT synced back to the host - The
node_modulessymlink appears as a broken link on the host — this is harmless sincenode_modulesis typically gitignored - Running
npm ciornpm installon the host naturally replaces the symlink with a real directory - After any
package.jsonorpackage-lock.jsonchange, re-run the install script - Do NOT run
npm ciornpm installdirectly in the mounted workspace — native binaries will crash
Troubleshooting
| Problem | Solution |
|---|---|
SIGILL or SIGSEGV when running dev server |
Re-run the install script; ensure you're not running npm install directly in the workspace |
node_modules not found after install |
Check that the symlink exists: ls -la node_modules |
| Permission errors during install | Ensure the local deps directory is writable by the current user |
| Verification fails intermittently | Run the script again — native binary crashes can be non-deterministic on first load |
Vite Compatibility
If your project uses Vite, you may need to allow the symlinked path in server.fs.allow. Add the symlink target's parent directory (e.g., /home/agent/project-deps/) to your Vite config so that Vite can serve files through the symlink.
常见问题
我为什么不能直接正常使用 `npm install`?
在某些使用 “virtiofs” 技术的隔离环境(沙箱)中,原生编译的程序(如 esbuild、lightningcss)可能会失败。这个工具通过把软件包安装到沙箱内的另一个安全位置,绕过了这个问题。
已安装的软件包会怎样?
软件包安装在沙箱内的一个目录中,该目录不会同步回你的主电脑。你的项目通过快捷方式访问这些软件包,而该目录本身保持隔离。
运行这个工具后,我还需要做什么?
需要。安装完成后,你应该通过运行测试(`npm test`)、构建(`npm run build`)或启动开发服务器(`npm run dev`)来确认项目运行正常。
详情
作者的原始描述
Install npm packages in a Docker sandbox environment. Use this skill whenever you need to install, reinstall, or update node_modules inside a container where the workspace is mounted via virtiofs. Native binaries (esbuild, lightningcss, rollup) crash on virtiofs, so packages must be installed on the local ext4 filesystem and symlinked back.
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7415
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。