Описание
Node.js Sandbox MCP Server vulnerability can lead to Sandbox Escape via Command Injection
Summary
A command injection vulnerability exists in the node-code-sandbox-mcp MCP Server. The vulnerability is caused by the unsanitized use of input parameters within a call to child_process.execSync, enabling an attacker to inject arbitrary system commands. Successful exploitation can lead to remote code execution under the server process's privileges on the host machine, bypassing the sandbox protection of running code inside docker.
The server constructs and executes shell commands using unvalidated user input directly within command-line strings. This introduces the possibility of shell metacharacter injection (|, >, &&, etc.).
Details
The MCP Server exposes tools to run code inside a docker container. An MCP Client can be instructed to execute additional actions for example via indirect prompt injection when asked to generate code that read a file. Below some example of vulnerable code and different ways to test this vulnerability including a real example of indirect prompt injection that can lead to arbitrary command injection (bypassing sandboxing).
Vulnerable code
The following snippet illustrates the vulnerable code pattern used in the MCP Server’s tooling. Note: These is only one instance, but similar patterns may exist elsewhere in the codebase.
PoC
Setup
- download a docker image and create folder to store a (malicious) file
Realistic Example - Indirect prompt injection via file content
- in the
~/shareddirectory, create a file namedtest.txtwith the following content to simulate untrusted content that should be processed inside the container:
- Verify the file
/tmp/TEST1 does not exist (on the host machine):
- setup your client IDE (replace
/path/to/sharedwith the folder wheretest.txtis saved)
- open the chat and enter the following prompt (it's an example)
- run the
run_js_epehemeraltool. The request will look like the following (i.e js code that reads the file and prints the output):
- Observe that the response will contain the file content but will also trigger the
sandbox_stoptool execution with a malicious payload that can lead to command injection on the host machine - run the
sandbox_stoptool (if you have auto run functionality enabled this will be executed without user interaction)
Result:
- Confirm that the injected command executed on the host machine (not inside the container):
Another example (instead of reading a local file) would involve requesting the creation of JavaScript code that interacts with untrusted resources—such as fetching remote data or installing packages. In this case, I used a local file to simplify the PoC.
Using MCP Inspector
- Open the MCP Inspector:
-
In MCP Inspector:
- set transport type:
STDIO - set the
commandtonpx - set the arguments to
node-code-sandbox-mcp@latest - Add environment variable:
FILES_DIR=/tmp/data - click Connect
- go to the Tools tab and click List Tools
- select the
sandbox_stoptool
- set transport type:
-
Verify the file
/tmp/TESTdoes not exist:
- In the container_id field, input:
- Click Run Tool
- Observe the request being sent:
Response:
- Confirm that the injected command executed:
Remediation
To mitigate this vulnerability, I suggest to avoid using child_process.execSync with untrusted input. Instead, use a safer API such as child_process.execFileSync, which allows you to pass arguments as a separate array — avoiding shell interpretation entirely.
Impact
Command Injection / Remote Code Execution (RCE) / Sandbox escape
References
Ссылки
- https://github.com/alfonsograziano/node-code-sandbox-mcp/security/advisories/GHSA-5w57-2ccq-8w95
- https://nvd.nist.gov/vuln/detail/CVE-2025-53372
- https://github.com/alfonsograziano/node-code-sandbox-mcp/commit/a5e05fab06b20f2ce68326538c0d6cdf5512e10a
- https://github.com/alfonsograziano/node-code-sandbox-mcp/commit/af860e2258a81ba58f4bfff7ba17e641df0e1178
- https://github.com/alfonsograziano/node-code-sandbox-mcp/commit/e461a74ecb189b268daac0d972c467b49b2abdd2
Пакеты
node-code-sandbox-mcp
<= 1.2.0
1.3.0
Связанные уязвимости
node-code-sandbox-mcp is a Node.js–based Model Context Protocol server that spins up disposable Docker containers to execute arbitrary JavaScript. Prior to 1.3.0, a command injection vulnerability exists in the node-code-sandbox-mcp MCP Server. The vulnerability is caused by the unsanitized use of input parameters within a call to child_process.execSync, enabling an attacker to inject arbitrary system commands. Successful exploitation can lead to remote code execution under the server process's privileges on the host machine, bypassing the sandbox protection of running code inside docker. This vulnerability is fixed in 1.3.0.