agentboxes 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentboxes-0.2.2 → agentboxes-0.2.4}/PKG-INFO +1 -1
- {agentboxes-0.2.2 → agentboxes-0.2.4}/agentbox/__init__.py +8 -2
- {agentboxes-0.2.2 → agentboxes-0.2.4}/agentboxes.egg-info/PKG-INFO +1 -1
- {agentboxes-0.2.2 → agentboxes-0.2.4}/pyproject.toml +1 -1
- {agentboxes-0.2.2 → agentboxes-0.2.4}/tests/test_client.py +33 -0
- {agentboxes-0.2.2 → agentboxes-0.2.4}/README.md +0 -0
- {agentboxes-0.2.2 → agentboxes-0.2.4}/agentboxes.egg-info/SOURCES.txt +0 -0
- {agentboxes-0.2.2 → agentboxes-0.2.4}/agentboxes.egg-info/dependency_links.txt +0 -0
- {agentboxes-0.2.2 → agentboxes-0.2.4}/agentboxes.egg-info/top_level.txt +0 -0
- {agentboxes-0.2.2 → agentboxes-0.2.4}/setup.cfg +0 -0
|
@@ -63,7 +63,7 @@ class Agentbox:
|
|
|
63
63
|
self,
|
|
64
64
|
template: Optional[str] = None,
|
|
65
65
|
allow_hosts: Optional[List[str]] = None,
|
|
66
|
-
secrets: Optional[
|
|
66
|
+
secrets: Optional[List[str]] = None,
|
|
67
67
|
memory_mb: Optional[int] = None,
|
|
68
68
|
cpus: Optional[float] = None,
|
|
69
69
|
disk_mb: Optional[int] = None,
|
|
@@ -202,10 +202,16 @@ class Sandbox:
|
|
|
202
202
|
|
|
203
203
|
# Writes a sandbox directory's contents into a local directory, refusing members that would leave it.
|
|
204
204
|
def download_directory(self, directory: str, local_dir: str) -> None:
|
|
205
|
+
base = os.path.realpath(local_dir)
|
|
206
|
+
os.makedirs(base, exist_ok=True)
|
|
205
207
|
with tarfile.open(fileobj=io.BytesIO(self.download_tar(directory)), mode="r") as archive:
|
|
206
208
|
for member in archive.getmembers():
|
|
207
|
-
if member.
|
|
209
|
+
if member.issym() or member.islnk() or member.isdev():
|
|
210
|
+
raise AgentboxError(f"archive from the sandbox has a link or device member: {member.name}", 0, "UnsafeArchive")
|
|
211
|
+
target = os.path.realpath(os.path.join(base, member.name))
|
|
212
|
+
if target != base and not target.startswith(base + os.sep):
|
|
208
213
|
raise AgentboxError(f"archive from the sandbox has an unsafe path: {member.name}", 0, "UnsafeArchive")
|
|
214
|
+
member.mode &= 0o777 # drop setuid, setgid and sticky bits so an extracted file cannot carry them
|
|
209
215
|
archive.extractall(local_dir)
|
|
210
216
|
|
|
211
217
|
def egress_log(self) -> Dict[str, Any]:
|
|
@@ -70,6 +70,39 @@ class ClientTest(unittest.TestCase):
|
|
|
70
70
|
finally:
|
|
71
71
|
box.destroy()
|
|
72
72
|
|
|
73
|
+
def test_download_directory_refuses_a_symlink_out_of_the_folder(self):
|
|
74
|
+
box = self.client.create()
|
|
75
|
+
try:
|
|
76
|
+
with tempfile.TemporaryDirectory() as src, tempfile.TemporaryDirectory() as out:
|
|
77
|
+
os.symlink(out, os.path.join(src, "link"))
|
|
78
|
+
box.upload_directory(src, "escape")
|
|
79
|
+
with self.assertRaises(AgentboxError) as caught:
|
|
80
|
+
box.download_directory("escape", out)
|
|
81
|
+
self.assertEqual(caught.exception.code, "UnsafeArchive")
|
|
82
|
+
finally:
|
|
83
|
+
box.destroy()
|
|
84
|
+
|
|
85
|
+
def test_download_directory_strips_setuid_bits(self):
|
|
86
|
+
import io
|
|
87
|
+
import stat
|
|
88
|
+
import tarfile
|
|
89
|
+
|
|
90
|
+
box = self.client.create()
|
|
91
|
+
try:
|
|
92
|
+
buf = io.BytesIO()
|
|
93
|
+
with tarfile.open(fileobj=buf, mode="w") as archive:
|
|
94
|
+
info = tarfile.TarInfo("tool")
|
|
95
|
+
info.size = 2
|
|
96
|
+
info.mode = 0o4755
|
|
97
|
+
archive.addfile(info, io.BytesIO(b"hi"))
|
|
98
|
+
box.upload_tar(buf.getvalue(), "proj")
|
|
99
|
+
with tempfile.TemporaryDirectory() as out:
|
|
100
|
+
box.download_directory("proj", out)
|
|
101
|
+
mode = os.stat(os.path.join(out, "tool")).st_mode
|
|
102
|
+
self.assertFalse(mode & stat.S_ISUID)
|
|
103
|
+
finally:
|
|
104
|
+
box.destroy()
|
|
105
|
+
|
|
73
106
|
def test_typed_errors(self):
|
|
74
107
|
with self.assertRaises(SandboxNotFound):
|
|
75
108
|
self.client.get("sbx_nope")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|