Skip to content

Commit 16807f0

Browse files
committed
chore: Update tmpfs configuration and directory structure in Docker setup
- Added a temporary filesystem configuration for /tmp with size and mode settings in both Docker Compose files. - Changed the directory for empty_proc from /tmp to /var/lib/code-interpreter in the Dockerfile and related service files. - Updated the sandbox execution commands to reflect the new empty_proc path and incorporated dynamic tmpfs size settings.
1 parent 25e8fed commit 16807f0

6 files changed

Lines changed: 20 additions & 4 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
233233
# ============================================
234234
RUN mkdir -p /var/lib/code-interpreter/sandboxes && \
235235
mkdir -p /mnt/data && \
236-
mkdir -p /tmp/empty_proc
236+
mkdir -p /var/lib/code-interpreter/empty_proc
237237

238238
RUN groupadd -g 1001 codeuser && \
239239
useradd -u 1001 -g codeuser -m codeuser && \

docker-compose.prod.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
# to the mounted files inside the container under /app/ssl.
3131
- ${SSL_CERTS_PATH:-./ssl}:/app/ssl:ro
3232
tmpfs:
33+
- /tmp:size=512m,mode=1777
3334
- /app/data:size=100m
3435
depends_on:
3536
redis:

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
# to the mounted files inside the container under /app/ssl.
3131
- ${SSL_CERTS_PATH:-./ssl}:/app/ssl:ro
3232
tmpfs:
33+
- /tmp:size=512m,mode=1777
3334
- /app/data:size=100m
3435
depends_on:
3536
redis:

src/services/programmatic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ async def start_execution(
186186
shlex.quote(str(a)) for a in [settings.nsjail_binary] + nsjail_args
187187
)
188188

189+
tmpfs_size = settings.sandbox_tmpfs_size_mb
190+
189191
wrapper_cmd = (
190192
f"mount --bind {shlex.quote(str(sandbox_info.data_dir))} /mnt/data && "
191193
f"mount -t tmpfs -o size=1k tmpfs /var/lib/code-interpreter/sandboxes && "
@@ -194,7 +196,9 @@ async def start_execution(
194196
f"mount -t tmpfs -o size=1k tmpfs /app/ssl && "
195197
f"mount -t tmpfs -o size=1k tmpfs /app/dashboard && "
196198
f"mount -t tmpfs -o size=1k tmpfs /app/src && "
197-
f"mount --bind /tmp/empty_proc /proc && "
199+
f"mount --bind /var/lib/code-interpreter/empty_proc /proc && "
200+
# BUG-007: Ephemeral /tmp — prevent cross-session data persistence
201+
f"mount -t tmpfs -o size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
198202
f"{nsjail_cmd}"
199203
)
200204

src/services/sandbox/executor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ async def execute_command(
103103
if lang in ("java", "rs", "bash"):
104104
proc_mask = ""
105105
else:
106-
proc_mask = "mount --bind /tmp/empty_proc /proc && "
106+
proc_mask = (
107+
"mount --bind /var/lib/code-interpreter/empty_proc /proc && "
108+
)
109+
110+
tmpfs_size = settings.sandbox_tmpfs_size_mb
107111

108112
wrapper_cmd = (
109113
# Bind sandbox dir to /mnt/data (before hiding sandboxes dir)
@@ -120,6 +124,8 @@ async def execute_command(
120124
f"mount -t tmpfs -o size=1k tmpfs /app/src && "
121125
# BUG-003: Hide /proc (except Java which needs /proc/self/exe)
122126
f"{proc_mask}"
127+
# BUG-007: Ephemeral /tmp — prevent cross-session data persistence
128+
f"mount -t tmpfs -o size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
123129
# Execute nsjail
124130
f"{nsjail_cmd}"
125131
)

src/services/sandbox/pool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ async def _start_repl_process(
390390
nsjail_cmd = " ".join(
391391
shlex.quote(str(a)) for a in [settings.nsjail_binary] + nsjail_args
392392
)
393+
tmpfs_size = settings.sandbox_tmpfs_size_mb
394+
393395
wrapper_cmd = (
394396
# Bind sandbox dir to /mnt/data (before hiding sandboxes dir)
395397
f"mount --bind {shlex.quote(str(sandbox_info.data_dir))} /mnt/data && "
@@ -404,7 +406,9 @@ async def _start_repl_process(
404406
f"mount -t tmpfs -o size=1k tmpfs /app/dashboard && "
405407
f"mount -t tmpfs -o size=1k tmpfs /app/src && "
406408
# BUG-003: Hide /proc (REPL is Python-only, always safe to mask)
407-
f"mount --bind /tmp/empty_proc /proc && "
409+
f"mount --bind /var/lib/code-interpreter/empty_proc /proc && "
410+
# BUG-007: Ephemeral /tmp — prevent cross-session data persistence
411+
f"mount -t tmpfs -o size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
408412
# Execute nsjail
409413
f"{nsjail_cmd}"
410414
)

0 commit comments

Comments
 (0)