Skip to content

Commit 504d381

Browse files
GeekTrainerCopilot
andcommitted
feat: add sandbox-npm-install skill to community collection
Add a reusable Agent Skill that installs npm packages in Docker sandbox environments where virtiofs-mounted workspaces cause native binary crashes (esbuild, lightningcss, rollup). The script installs on local ext4 and symlinks node_modules back into the workspace. - SKILL.md with spec-compliant frontmatter and documentation - scripts/install.sh with security hardening (no eval, readonly paths) - Updated docs/README.skills.md with new skill entry Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cf0820a commit 504d381

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed

docs/README.skills.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ See [CONTRIBUTING.md](../CONTRIBUTING.md#adding-skills) for guidelines on how to
209209
| [reviewing-oracle-to-postgres-migration](../skills/reviewing-oracle-to-postgres-migration/SKILL.md) | Identifies Oracle-to-PostgreSQL migration risks by cross-referencing code against known behavioral differences (empty strings, refcursors, type coercion, sorting, timestamps, concurrent transactions, etc.). Use when planning a database migration, reviewing migration artifacts, or validating that integration tests cover Oracle/PostgreSQL differences. | `references/REFERENCE.md`<br />`references/empty-strings-handling.md`<br />`references/no-data-found-exceptions.md`<br />`references/oracle-parentheses-from-clause.md`<br />`references/oracle-to-postgres-sorting.md`<br />`references/oracle-to-postgres-timestamp-timezone.md`<br />`references/oracle-to-postgres-to-char-numeric.md`<br />`references/oracle-to-postgres-type-coercion.md`<br />`references/postgres-concurrent-transactions.md`<br />`references/postgres-refcursor-handling.md` |
210210
| [ruby-mcp-server-generator](../skills/ruby-mcp-server-generator/SKILL.md) | Generate a complete Model Context Protocol server project in Ruby using the official MCP Ruby SDK gem. | None |
211211
| [rust-mcp-server-generator](../skills/rust-mcp-server-generator/SKILL.md) | Generate a complete Rust Model Context Protocol server project with tools, prompts, resources, and tests using the official rmcp SDK | None |
212+
| [sandbox-npm-install](../skills/sandbox-npm-install/SKILL.md) | 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. | `scripts/install.sh` |
212213
| [scaffolding-oracle-to-postgres-migration-test-project](../skills/scaffolding-oracle-to-postgres-migration-test-project/SKILL.md) | Scaffolds an xUnit integration test project for validating Oracle-to-PostgreSQL database migration behavior in .NET solutions. Creates the test project, transaction-rollback base class, and seed data manager. Use when setting up test infrastructure before writing migration integration tests, or when a test project is needed for Oracle-to-PostgreSQL validation. | None |
213214
| [scoutqa-test](../skills/scoutqa-test/SKILL.md) | This skill should be used when the user asks to "test this website", "run exploratory testing", "check for accessibility issues", "verify the login flow works", "find bugs on this page", or requests automated QA testing. Triggers on web application testing scenarios including smoke tests, accessibility audits, e-commerce flows, and user flow validation using ScoutQA CLI. IMPORTANT: Use this skill proactively after implementing web application features to verify they work correctly - don't wait for the user to ask for testing. | None |
214215
| [shuffle-json-data](../skills/shuffle-json-data/SKILL.md) | Shuffle repetitive JSON objects safely by validating schema consistency before randomising entries. | None |
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
name: sandbox-npm-install
3+
description: '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.'
4+
---
5+
6+
# Sandbox npm Install
7+
8+
## When to Use This Skill
9+
10+
Use this skill whenever:
11+
- You need to install npm packages for the first time in a new sandbox session
12+
- `package.json` or `package-lock.json` has changed and you need to reinstall
13+
- You encounter native binary crashes with errors like `SIGILL`, `SIGSEGV`, `mmap`, or `unaligned sysNoHugePageOS`
14+
- The `node_modules` directory is missing or corrupted
15+
16+
## Prerequisites
17+
18+
- A Docker sandbox environment with a virtiofs-mounted workspace
19+
- Node.js and npm available in the container
20+
- A `package.json` file in the target workspace
21+
22+
## Background
23+
24+
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.
25+
26+
## Step-by-Step Installation
27+
28+
Run the bundled install script from the workspace root:
29+
30+
```bash
31+
bash scripts/install.sh
32+
```
33+
34+
### Common Options
35+
36+
| Option | Description |
37+
|---|---|
38+
| `--workspace <path>` | Path to directory containing `package.json` (auto-detected if omitted) |
39+
| `--playwright` | Also install Playwright Chromium browser for E2E testing |
40+
41+
### What the Script Does
42+
43+
1. Copies `package.json`, `package-lock.json`, and `.npmrc` (if present) to a local ext4 directory
44+
2. Runs `npm ci` (or `npm install` if no lockfile) on the local filesystem
45+
3. Symlinks `node_modules` back into the workspace
46+
4. Verifies known native binaries (esbuild, rollup, lightningcss, vite) if present
47+
5. Optionally installs Playwright browsers
48+
49+
If verification fails, run the script again — crashes can be intermittent during initial setup.
50+
51+
## Post-Install Verification
52+
53+
After the script completes, verify your toolchain works. For example:
54+
55+
```bash
56+
npm test # Run project tests
57+
npm run build # Build the project
58+
npm run dev # Start dev server
59+
```
60+
61+
## Important Notes
62+
63+
- The local install directory (e.g., `/home/agent/project-deps`) is **container-local** and is NOT synced back to the host
64+
- The `node_modules` symlink appears as a broken link on the host — this is harmless since `node_modules` is typically gitignored
65+
- Running `npm ci` or `npm install` on the host naturally replaces the symlink with a real directory
66+
- After any `package.json` or `package-lock.json` change, re-run the install script
67+
- Do NOT run `npm ci` or `npm install` directly in the mounted workspace — native binaries will crash
68+
69+
## Troubleshooting
70+
71+
| Problem | Solution |
72+
|---|---|
73+
| `SIGILL` or `SIGSEGV` when running dev server | Re-run the install script; ensure you're not running `npm install` directly in the workspace |
74+
| `node_modules` not found after install | Check that the symlink exists: `ls -la node_modules` |
75+
| Permission errors during install | Ensure the local deps directory is writable by the current user |
76+
| Verification fails intermittently | Run the script again — native binary crashes can be non-deterministic on first load |
77+
78+
## Vite Compatibility
79+
80+
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.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Sandbox npm Install Script
5+
# Installs node_modules on local ext4 filesystem and symlinks into the workspace.
6+
# This avoids native binary crashes (esbuild, lightningcss, rollup) on virtiofs.
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
10+
11+
# Local ext4 base directory where node_modules is installed to avoid virtiofs crashes.
12+
# Change this path if your sandbox uses a different local filesystem location.
13+
readonly DEPS_BASE="/home/agent/project-deps"
14+
WORKSPACE_CLIENT=""
15+
INSTALL_PLAYWRIGHT="false"
16+
17+
usage() {
18+
cat <<EOF
19+
Usage: $(basename "$0") [options]
20+
21+
Options:
22+
--workspace <path> Client workspace containing package.json
23+
--playwright Install Playwright Chromium browser
24+
--help Show this help message
25+
26+
Examples:
27+
bash scripts/install.sh
28+
bash scripts/install.sh --workspace app/client --playwright
29+
EOF
30+
}
31+
32+
while [[ $# -gt 0 ]]; do
33+
case "$1" in
34+
--workspace)
35+
if [[ -z "${2:-}" ]]; then
36+
echo "Error: --workspace requires a path argument"
37+
usage
38+
exit 1
39+
fi
40+
WORKSPACE_CLIENT="$2"
41+
shift 2
42+
;;
43+
--playwright)
44+
INSTALL_PLAYWRIGHT="true"
45+
shift
46+
;;
47+
--help|-h)
48+
usage
49+
exit 0
50+
;;
51+
*)
52+
echo "Unknown option: $1"
53+
usage
54+
exit 1
55+
;;
56+
esac
57+
done
58+
59+
if [[ -z "$WORKSPACE_CLIENT" ]]; then
60+
if [[ -f "$PWD/package.json" ]]; then
61+
WORKSPACE_CLIENT="$PWD"
62+
elif [[ -f "$REPO_ROOT/package.json" ]]; then
63+
WORKSPACE_CLIENT="$REPO_ROOT"
64+
fi
65+
fi
66+
67+
WORKSPACE_CLIENT="$(cd "$WORKSPACE_CLIENT" 2>/dev/null && pwd || true)"
68+
69+
if [[ -z "$WORKSPACE_CLIENT" || ! -f "$WORKSPACE_CLIENT/package.json" ]]; then
70+
echo "Could not find a valid workspace client path containing package.json."
71+
echo "Use --workspace <path> to specify it explicitly."
72+
exit 1
73+
fi
74+
75+
echo "=== Sandbox npm Install ==="
76+
echo "Workspace: $WORKSPACE_CLIENT"
77+
78+
# Derive a unique subdirectory from the workspace path relative to the repo root.
79+
# e.g. /repo/apps/web -> apps-web, /repo -> <repo-basename>
80+
REL_PATH="${WORKSPACE_CLIENT#"$REPO_ROOT"}"
81+
REL_PATH="${REL_PATH#/}"
82+
if [[ -z "$REL_PATH" ]]; then
83+
REL_PATH="$(basename "$REPO_ROOT")"
84+
fi
85+
# Sanitize: replace path separators with hyphens
86+
DEPS_SUBDIR="${REL_PATH//\//-}"
87+
DEPS_DIR="${DEPS_BASE}/${DEPS_SUBDIR}"
88+
89+
echo "Deps dir: $DEPS_DIR"
90+
91+
# Step 1: Prepare local deps directory
92+
echo "→ Preparing $DEPS_DIR..."
93+
rm -rf "$DEPS_DIR"
94+
mkdir -p "$DEPS_DIR"
95+
cp "$WORKSPACE_CLIENT/package.json" "$DEPS_DIR/"
96+
97+
# Copy .npmrc if present (needed for private registries / scoped packages)
98+
if [[ -f "$WORKSPACE_CLIENT/.npmrc" ]]; then
99+
cp "$WORKSPACE_CLIENT/.npmrc" "$DEPS_DIR/"
100+
fi
101+
102+
if [[ -f "$WORKSPACE_CLIENT/package-lock.json" ]]; then
103+
cp "$WORKSPACE_CLIENT/package-lock.json" "$DEPS_DIR/"
104+
INSTALL_CMD=(npm ci)
105+
else
106+
echo "! package-lock.json not found; falling back to npm install"
107+
INSTALL_CMD=(npm install)
108+
fi
109+
110+
# Step 2: Install on local ext4
111+
echo "→ Running ${INSTALL_CMD[*]} on local ext4..."
112+
cd "$DEPS_DIR" && "${INSTALL_CMD[@]}"
113+
114+
# Step 3: Symlink into workspace
115+
echo "→ Symlinking node_modules into workspace..."
116+
cd "$WORKSPACE_CLIENT"
117+
rm -rf node_modules
118+
ln -s "$DEPS_DIR/node_modules" node_modules
119+
120+
has_dep() {
121+
local dep="$1"
122+
node -e "
123+
const pkg=require(process.argv[1]);
124+
const deps={...(pkg.dependencies||{}),...(pkg.devDependencies||{})};
125+
process.exit(deps[process.argv[2]] ? 0 : 1);
126+
" "$WORKSPACE_CLIENT/package.json" "$dep"
127+
}
128+
129+
verify_one() {
130+
local label="$1"
131+
shift
132+
if "$@" >/dev/null 2>&1; then
133+
echo "$label OK"
134+
return 0
135+
fi
136+
137+
echo "$label FAIL"
138+
return 1
139+
}
140+
141+
# Step 4: Verify native binaries when present in this project
142+
echo "→ Verifying native binaries..."
143+
FAIL=0
144+
145+
if has_dep esbuild; then
146+
verify_one "esbuild" node -e "require('esbuild').transform('const x: number = 1',{loader:'ts'}).catch(()=>process.exit(1))" || FAIL=1
147+
fi
148+
149+
if has_dep rollup; then
150+
verify_one "rollup" node -e "import('rollup').catch(()=>process.exit(1))" || FAIL=1
151+
fi
152+
153+
if has_dep lightningcss; then
154+
verify_one "lightningcss" node -e "try{require('lightningcss')}catch(_){process.exit(1)}" || FAIL=1
155+
fi
156+
157+
if has_dep vite; then
158+
verify_one "vite" node -e "import('vite').catch(()=>process.exit(1))" || FAIL=1
159+
fi
160+
161+
if [ "$FAIL" -ne 0 ]; then
162+
echo "✗ Binary verification failed. Try running the script again (crashes can be intermittent)."
163+
exit 1
164+
fi
165+
166+
# Step 5: Optionally install Playwright
167+
if [[ "$INSTALL_PLAYWRIGHT" == "true" ]]; then
168+
echo "→ Installing Playwright browsers..."
169+
if [[ "${EUID:-$(id -u)}" -eq 0 ]]; then
170+
npx playwright install --with-deps chromium
171+
else
172+
npx playwright install chromium
173+
fi
174+
fi
175+
176+
echo ""
177+
echo "=== ✓ Sandbox npm install complete ==="
178+
echo "Run 'npm run dev' to start the dev server."

0 commit comments

Comments
 (0)