fix(sdk): prevent shell injection in MCP config via proper escaping#1276
Open
kagura-agent wants to merge 3 commits intoe2b-dev:mainfrom
Open
fix(sdk): prevent shell injection in MCP config via proper escaping#1276kagura-agent wants to merge 3 commits intoe2b-dev:mainfrom
kagura-agent wants to merge 3 commits intoe2b-dev:mainfrom
Conversation
…llQuote Use shlex.quote() (Python) and a shellQuote() helper (JS/TS) to properly escape the JSON-serialized MCP config before interpolating it into the shell command. Previously, single quotes in config values (API keys, tokens, URLs) could break out of shell quoting and allow arbitrary command execution inside the sandbox. Fixes e2b-dev#1154
🦋 Changeset detectedLatest commit: 89fe756 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1154
When creating a sandbox with an
mcpconfig, the JSON-serialized config is interpolated directly into a shell command wrapped in single quotes. Sincejson.dumps()/JSON.stringify()do not escape single quotes, any MCP config value containing a single quote (e.g., API keys, tokens, URLs) breaks out of shell quoting and allows arbitrary command execution inside the sandbox.Changes
Python SDK (
sandbox_async/main.py,sandbox_sync/main.py)shlex.quote()to properly escape the JSON config string (4 locations)shlex.quote()is a stdlib function designed exactly for this purposeJS/TS SDK (
sandbox/index.ts)shellQuote()helper that escapes single quotes using the standard'\'''pattern (equivalent to Python'sshlex.quote())Before / After
Before (vulnerable):
After (safe):
Testing
Verified escaping behavior for both Python (
shlex.quote) and JS (shellQuote) with the PoC from the issue — single quotes in config values are properly escaped and no longer allow shell breakout.