跳到正文
Skillpedia
部署与云(DevOps)40k · #7415

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/sandbox-npm-install/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.json or package-lock.json has changed and you need to reinstall
  • You encounter native binary crashes with errors like SIGILL, SIGSEGV, mmap, or unaligned sysNoHugePageOS
  • The node_modules directory is missing or corrupted

Prerequisites

  • A Docker sandbox environment with a virtiofs-mounted workspace
  • Node.js and npm available in the container
  • A package.json file 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

  1. Copies package.json, package-lock.json, and .npmrc (if present) to a local ext4 directory
  2. Runs npm ci (or npm install if no lockfile) on the local filesystem
  3. Symlinks node_modules back into the workspace
  4. Verifies known native binaries (esbuild, rollup, lightningcss, vite) if present
  5. Optionally installs Playwright browsers and system dependencies (uses sudo when 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_modules symlink appears as a broken link on the host — this is harmless since node_modules is typically gitignored
  • Running npm ci or npm install on the host naturally replaces the symlink with a real directory
  • After any package.json or package-lock.json change, re-run the install script
  • Do NOT run npm ci or npm install directly 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能