Zero-trust procedure for reviewing or running code from an unknown source. Use when reviewing, vetting, cloning, installing, or running code from an untrusted source (repo invites, packages, scripts, executable config files), when asked whether code is safe or hazardous, when executed code may read secrets/files or reach the network, and when the user says "raise hands", "stop and alert", or "sandbox it". Also trigger on suspicion of malicious, harmful, deceptive, cheating, or stealing behavior.
---
name: untrusted-code-safety
description: >
Zero-trust procedure for reviewing or running code from an unknown source.
Use when reviewing, vetting, cloning, installing, or running code from an
untrusted source (repo invites, packages, scripts, executable config files),
when asked whether code is safe or hazardous, when executed code may read
secrets/files or reach the network, and when the user says "raise hands",
"stop and alert", or "sandbox it". Also trigger on suspicion of malicious,
harmful, deceptive, cheating, or stealing behavior.
---
# Untrusted code safety
A zero-trust procedure for handling code you do not control. It records the standing contract the user requires, then the workflow to honor it. When in doubt, stop and ask — never assume.
## Standing contract (hard boundaries — never cross)
- `/tmp` is the only workspace for untrusted code. Never let it read, collect, or send data from this machine outside `/tmp`.
- Never read the user's personal files outside the sandbox — their code, API keys, credentials, SSH/GPG keys, wallets, or browser sessions.
- Never trust code from an unknown source. A repo invite, a polished README, a long commit history, a familiar package name — none of it is a vouch.
- Delete every test clone and artifact when done.
## STOP + RAISE HANDS immediately
Halt the run, do not continue, and report to the user at once (with what was attempted, the path/target, and the evidence) if any executed code:
1. reads the filesystem **outside `/tmp`** (or outside the declared sandbox);
2. touches sensitive data — `process.env`, API keys, tokens, credentials, SSH/Git config, wallets;
3. collects **or** sends any local data off the machine;
4. spawns child processes or opens network connections that were not explicitly authorized;
5. shows any malicious, harmful, deceptive, cheating, or stealing behavior.
Raising hands is not a status update — it is a hard stop. Do not "finish the run first". Do not bury it. Surface it in the next message.
## Confirm first when unsure
If the sandbox boundary, the intent, or the safety of an action is unclear, ask the user before proceeding. A wrong assumption here is expensive.
**Default: do not execute.** Static triage is usually enough. Escalate to a sandboxed run only when the question cannot be answered statically, and get the user's explicit go-ahead before any Level-2 execution (step 3 below).
## Procedure
1. **Detect (static, no execution).** Decide as much as possible from metadata and text; most verdicts need no run.
2. **Sensitivity.** Inventory what a process running as the user could reach before running anything.
3. **Contain.** Execute only inside stacked isolation if execution is truly needed.
4. **Instrument.** Make the harness log and block `fs`/`env`/network/child-process reach and scream on violations.
5. **Decide.** Static + contained evidence → verdict; never execute at "trust level 3".
6. **Clean up.** Remove clones/artifacts; report to the platform if malicious.
### Trust ladder (escalate only with reason)
| Level | Action | Safe on daily driver? |
|-------|--------|-----------------------|
| 0 | Metadata only (`gh api`, `git log`, sizes, dates) | yes |
| 1 | Read/triage files as plain text (no build, no eval) | yes |
| 2 | Execute in a throwaway sandbox: no network, no secrets, cleared env, non-root, fs allowlist | contained |
| 3 | Execute with host mounts / credentials / network | **never** for untrusted code |
### Detection commands
```bash
git log --format='%h %ad %an <%ae> %s' --date=iso | head -40
git shortlog -sne
find . -type f -not -path './.git/*' -size +500k -printf '%s\t%p\n' | sort -rn
rg -l --hidden -g '!**/node_modules/**' 'eval\(|Function\(|atob\(|Buffer\.from\(|fromCharCode'
rg -n '(pre|post)?(install|prepare|pack|publish)' package.json **/package.json 2>/dev/null
rg -n 'require\(|import ' tailwind.config.js postcss.config.js babel.config.js webpack.config.js config-overrides.js 2>/dev/null
rg -n 'child_process|execSync|spawn|process\.env|os\.homedir|\.ssh|id_rsa|wallet|mnemonic|privateKey' -g '!**/node_modules/**'
npm view <pkg> repository dist.tarball time.modified
```
Other tells: a single giant line, rotated string arrays, hex/base64 blobs,
`--no-save`, `npm install` inside build scripts, `curl|sh`, config files that
`require` code, and lifecycle hooks (`preinstall`/`install`/`postinstall`/`prepare`).
### Defang before you sandbox
- Prefer `npm ci --ignore-scripts` (or `npm install --ignore-scripts`) — lifecycle hooks never run, for any untrusted dependency tree.
- `npm config set ignore-scripts true` for the session, and `git config --global core.hooksPath /dev/null` to neutralize repo hooks.
- Run with a scrubbed environment and a throwaway `HOME`; never install with real credentials in scope.
### Provenance (earn trust, don't assume it)
- `sha256sum <file>` and compare against a trusted source.
- `git verify-commit <sha>` or `git log --show-signature` for signed history.
- `npm audit signatures` for registry provenance/attestations.
- `gh attestation verify <artifact> --repo <owner>/<repo>` for GitHub build attestations.
- Pin versions and review any lockfile change with `git diff`.
### Containment recipe (Linux, unprivileged)
Create the work dir first (`mkdir -p /tmp/opencode/sbx/work`), and adjust `/usr`, `/bin`, `/lib*`, and `/etc/ld.so.cache` for the distro — these bind paths are glibc/Arch-shaped.
```bash
bwrap --unshare-all --die-with-parent --new-session \
--ro-bind /usr /usr --ro-bind /bin /bin --ro-bind /lib /lib --ro-bind /lib64 /lib64 \
--ro-bind /etc/ld.so.cache /etc/ld.so.cache \
--proc /proc --dev /dev --tmpfs /tmp \
--bind /tmp/opencode/sbx/work /work \
--chdir /work --clearenv --setenv PATH /usr/bin --setenv HOME /work \
--uid 65534 --gid 65534 \
/usr/bin/bash -c 'your-harness'
```
- `--unshare-all` gives no network interface and no DNS; `--clearenv` drops all secrets; `nobody` drops privilege; only the sandbox dir is mounted.
- Add Node `--permission --allow-fs-read=/work --allow-fs-write=/work` as a second, kernel-enforced layer.
- Verify the boundary **in the same invocation** before loading the payload: a real host path (e.g. the user's home) is absent, `getent hosts github.com` returns no DNS, and `id` shows `nobody`.
- Stage fake `socket.io-client` / `axios` / `sql.js` / `form-data` modules that only log their arguments, to reveal C2 targets without real network.
### Alerting instrumentation
Minimal interception skeleton (run inside the sandbox, before loading the payload):
```js
const Module = require("module");
const realLoad = Module._load;
const noop = (name) => new Proxy({}, { get: (_, p) => (...a) => console.log("[hit]", name, String(p), a[0] ?? "") });
Module._load = function (req) {
if (["child_process", "net", "tls", "http", "https", "dns", "http2", "dgram"].includes(req)) return noop(req);
return realLoad.apply(this, arguments);
};
```
- Replace/stub `child_process`, `net`, `tls`, `http`, `https`, `dns`, `http2`, `dgram`, `worker_threads`, and global `fetch` with logging no-ops.
- Proxy `fs` and `process.env`; log every path and sensitive key; hard-alarm on any access outside the allowlist root.
- Prefer packet-level views when available (`tcpdump`, `ss -tp`, `lsof -i`); if absent, say the containment of record is the namespace + Node-permission pairing.
- Honesty rule: interception is not a hermetic sandbox. If `process.env` is not proxied or only some `fs` functions are wrapped, say so explicitly — "no egress" is not "provably could not read local data".
## Decision flow
```
UNTRUSTED INPUT (repo · package · invite · script · config)
▼
RULE 1 — DETECT (static, no execution)
▼
RULE 2 — BE SENSITIVE (data inventory)
▼
RULE 3 — BE ALERTED (contain + instrument; raise hands on violation)
▼
VERDICT: MALICIOUS → quarantine · rotate · report · never run
▼
RULE 4 — NEVER TRUST (a pass at level N never grants level N+1)
```
## Reporting malicious repos
GitHub has **no abuse email** — use the web form: `https://support.github.com/contact/report-abuse?category=report-abuse&report=other&report_type=unspecified` (or the repo's About sidebar → **Report repository**). Category: **Malware** (AUP §5, `Active Malware or Exploits`) — **not** Phishing (AUP §4, deceiving a person into revealing information). GitHub's own `security.txt` points only to `https://hackerone.com/github`, which is for bugs in GitHub's products, not for third-party malicious repos.
## Worked example
See `ai-thoughts/docs/260929-brisova-malware-analysis.md` — a private repo invite (`zignaly-open-projects/Brisova`) whose obfuscated Tailwind plugin ran `npm install sql.js socket.io-client form-data axios --no-save` at build time. Verdict: malicious build-time payload; no egress occurred; clone deleted.
don't have the plugin yet? install it then click "run inline in claude" again.
A zero-trust procedure for handling code you do not control. It records the standing contract the user requires, then the workflow to honor it. When in doubt, stop and ask. Never assume.
This skill hardens your defenses against untrusted code by enforcing a zero-trust stance: static analysis first, sandboxed execution only when necessary, instrumented monitoring of filesystem/network/env/subprocess calls, and immediate escalation on any boundary violation. Use it whenever you review, vet, clone, install, or run code from unknown sources (repo invites, npm packages, shell scripts, build configs), when asked to judge code safety, or when you suspect malicious, deceptive, or data-stealing behavior. Default action is "do not execute"; static triage answers most questions.
Prerequisites:
bwrap) or equivalent container/namespace isolation for Level-2 containment. macOS/Windows require Docker or VM-based sandboxing instead.npm audit and optional npm view access to registry metadata) if analyzing npm packages.git verify-commit, git log --show-signature).rg) or equivalent grep-like tool for regex pattern scanning.tcpdump, lsof, ss for network-level instrumentation.gh) for attestation verification and repo metadata.External dependencies (no auth required for static triage):
npm view <pkg> / npm audit signatures) for package provenance; queries are unauthenticated but subject to rate limits (60 req/min anonymous).gh commands are used; respects GitHub's anonymous rate limit (60 req/hour).Data inventory (before execution):
~/.ssh, ~/.gnupg), credentials (~/.aws, ~/.config, ~/.kube), wallet files, browser session data, environment variables./tmp/opencode/sbx/work and standard system binaries/libs.Inputs: git repo, npm package, shell script, build config file, or source code listing.
Actions:
git log --format='%h %ad %an <%ae> %s' --date=iso | head -40 for recent commits, git shortlog -sne for author distribution, npm view <pkg> repository dist.tarball time.modified for package origin and age.rg to search for obfuscation markers (single giant lines, rotated string arrays, hex/base64 blobs), dangerous APIs (eval(, Function(, atob(, Buffer.from(, fromCharCode), subprocess spawning (child_process, execSync, spawn), environment access (process.env, os.homedir()), sensitive file paths (.ssh, id_rsa, wallet mnemonics, privateKey).rg -n '(pre|post)?(install|prepare|pack|publish)' package.json **/package.json 2>/dev/null and check for suspicious commands like npm install, curl|sh, or dynamic require() calls.require() or import statements that execute code at load time.find . -type f -not -path './.git/*' -size +500k -printf '%s\t%p\n' | sort -rn to spot hidden large blobs.Outputs: triage report (verdict: "safe to read", "suspicious / need deeper look", "malicious / stop immediately"), list of red-flag lines/files.
Edge cases:
Inputs: triage report from step 1; metadata on the user's local environment.
Actions:
Outputs: sensitivity scorecard (what's reachable, what's protected, what escalation is needed if the code is malicious).
Inputs: decision to execute (from decision points, below); a throwaway workspace at /tmp/opencode/sbx/work (or equivalent temp directory).
Setup (before payload execution):
mkdir -p /tmp/opencode/sbx/work && cd /tmp/opencode/sbx/work.npm ci --ignore-scripts or npm install --ignore-scripts to load dependencies without running lifecycle hooks. Set npm config set ignore-scripts true for the session. Also run git config --global core.hooksPath /dev/null to disable repo hooks.clearenv in the bubblewrap invocation; mount only the sandbox work dir and system binaries; drop to unprivileged user (uid 65534, nobody).--unshare-all in bubblewrap removes all network interfaces; verify with getent hosts github.com (should return nothing).id returns nobody.Execution (inside sandbox):
const Module = require("module");
const realLoad = Module._load;
const noop = (name) => new Proxy({}, {
get: (_, p) => (...a) => console.log("[INTERCEPTION]", name, String(p), a[0] ?? "")
});
Module._load = function (req) {
if (["child_process", "net", "tls", "http", "https", "dns", "http2", "dgram", "worker_threads"].includes(req)) {
return noop(req);
}
return realLoad.apply(this, arguments);
};
// also proxy fs.readFile, fs.readFileSync, fs.writeFile, process.env[key] with allowlist checks
fs calls and log every read/write path; alarm if any path is outside the allowlist root (/work).process.env access; log every key read; alarm on sensitive keys (AWS_, GITHUB_, PRIVATE, TOKEN, SECRET, etc.).child_process, net, tls, http, https, dns, http2, dgram, worker_threads, and global fetch with logging no-ops that record the destination host/command.socket.io-client, axios, sql.js, form-data) that only log arguments, to reveal command-and-control targets without real network egress.tcpdump, lsof -i, ss -tp) as a secondary layer if available.Outputs: execution transcript (all log messages from interception layer, including which APIs were called, which paths were accessed, which network destinations were attempted).
Edge cases:
bwrap markers or network interfaces): note the detection attempt as a red flag.fs is not fully proxied): state this explicitly in the report as "containment of record is namespace + Node-permission layers; fs.access() was not intercepted".Inputs: triage report (step 1), sensitivity scorecard (step 2), execution transcript (step 3, if executed).
Actions:
Outputs: verdict report (category, evidence, recommendation).
Never escalate to Level-3 (host credentials/network access) for untrusted code.
Trigger conditions (halt execution and report at once):
/tmp (or outside the declared sandbox).process.env keys, API credentials, SSH/GPG config, wallet files, or browser sessions.Action (not a status update; a hard stop):
Inputs: verdict (from step 4).
Actions:
rm -rf /tmp/opencode/sbx/work.Outputs: clean bill of execution; confirmation that artifacts were deleted.
Decision 1: Should we execute at all?
Decision 2: If static analysis is inconclusive, should we run a Level-2 sandbox?
Decision 3: Should we provision network access in the sandbox?
--unshare-all (no network). If the code needs network (e.g. it downloads a dependency), the user must explicitly request network access, understand the risk, and provide a list of allowed domains. Even then, use a proxy or firewall to enforce the allowlist at the kernel level.Decision 4: If the code is from a trusted source (GitHub org, npm org, signed commits), can we skip Level-2?
Decision 5: If the code has a large commit history or many stars, is it safe?
Decision 6: If we detect malicious behavior, should we "run it once more" to confirm?
Step 1 (Detect) outputs:
[RED] child_process spawn detected in lib/index.js:42 or [YELLOW] large binary blob (3.2 MB) in dist/app.wasm.Step 2 (Sensitivity) outputs:
HOME directory is reachable. SSH keys (~/.ssh) are reachable. Network access: none declared.Step 3 (Contain) outputs:
/tmp/opencode/sbx/work/sandbox.log.[INTERCEPTION] child_process spawn: ["npm", "install", ...] or [INTERCEPTION] fs.readFileSync: /work/package.json or [ALARM] fs.readFileSync: /home/user/.ssh/id_rsa.Step 4 (Decide) outputs:
VERDICT: MALICIOUS. Evidence: obfuscated Tailwind plugin runs npm install at build time, targeting sql.js and socket.io-client. No network egress confirmed in sandbox, but payload is designed for C2.Step 5 (Raise Hands) outputs:
Step 6 (Clean Up) outputs:
rm: removed directory '/tmp/opencode/sbx/work'.Success is:
Failure indicators:
/tmp or the declared sandbox./root, /.ssh, or other sensitive paths without alarm.# commit history and authorship
git log --format='%h %ad %an <%ae> %s' --date=iso | head -40
git shortlog -sne
# large files
find . -type f -not -path './.git/*' -size +500k -printf '%s\t%p\n' | sort -rn
# dangerous APIs and patterns
rg -l --hidden -g '!**/node_modules/**' 'eval\(|Function\(|atob\(|Buffer\.from\(|fromChar