Skip to content

Commit f24b49c

Browse files
committed
bwrap fixes
1 parent b9f28ad commit f24b49c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

shell_engine.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def _bwrap_prefix(self) -> list[str]:
8888
"--unshare-all",
8989
"--new-session",
9090
"--die-with-parent",
91+
"--dir",
92+
"/",
93+
"--chmod",
94+
"0555",
95+
"/",
9196
"--proc",
9297
"/proc",
9398
"--dev",
@@ -98,7 +103,7 @@ def _bwrap_prefix(self) -> list[str]:
98103
"PATH",
99104
"/usr/bin:/bin",
100105
"--chdir",
101-
"/",
106+
"/tmp",
102107
]
103108

104109
# Read-only bind common system locations needed for typical dynamic binaries

tests/test_bwrap_integration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ async def test_tmp_is_writable_tmpfs_and_readable_within_command():
5656
async def test_root_is_read_only_cannot_create_files():
5757
engine = await _new_engine()
5858

59-
# Attempt to write to /. If it were writable, we'd read back content; expect none.
59+
# Attempt to write to /. If it were writable, we'd read back content.
60+
# With proper sandboxing, awk will either fail to write (permission denied)
61+
# or print NOPE. Either way, WROTE should not appear.
6062
prog = (
6163
'BEGIN { f = "/mcpshell_should_fail"; '
6264
'print "x" > f; close(f); '
@@ -67,7 +69,7 @@ async def test_root_is_read_only_cannot_create_files():
6769
pipeline = [{"type": "command", "command": "awk", "args": [prog]}]
6870

6971
out = await engine.execute_pipeline(pipeline)
70-
assert "NOPE" in out
72+
assert "WROTE" not in out
7173

7274

7375
@pytest.mark.asyncio
@@ -84,4 +86,4 @@ async def test_usr_is_read_only_cannot_create_files():
8486
pipeline = [{"type": "command", "command": "awk", "args": [prog]}]
8587

8688
out = await engine.execute_pipeline(pipeline)
87-
assert "NOPE" in out
89+
assert "WROTE" not in out

0 commit comments

Comments
 (0)