Skip to content

Commit 2009e89

Browse files
authored
feat: Set TMPDIR for codejail executions (#36412)
This makes it easier to run matplotlib in codejail, and should prevent a number of other issues in the future with other packages that need to create tempfiles. No change is required for existing codejail installations, but after this change operators may be able to tighten their apparmor configuration to prevent write access to global temp or cache dirs. Manual testing instructions: Create a codejail problem that runs `import matplotlib` and confirm that it runs without error. (Unit tests aren't feasible here because this requires a fully configured codejail in order for the tmp subdirectory to exist.) Also: Add comment for `OPENBLAS_NUM_THREADS` and numpy support.
1 parent f877508 commit 2009e89

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: xmodule/capa/safe_exec/safe_exec.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
from __future__ import absolute_import, division
2222
2323
import os
24-
os.environ["OPENBLAS_NUM_THREADS"] = "1" # See TNL-6456
24+
25+
# openblas is a math library used by numpy. It will try to allocate multiple
26+
# threads by default, but this may exceed resource limits and cause a segfault.
27+
# Limiting to 1 thread will prevent this in all configurations.
28+
os.environ["OPENBLAS_NUM_THREADS"] = "1"
29+
30+
# Any code that uses the tempfile module to create temporary files should use
31+
# the ./tmp directory that codejail creates in each sandbox, rather than trying
32+
# to use a global temp dir (which should be blocked by AppArmor anyhow).
33+
# This is needed for matplotlib among other things.
34+
os.environ["TMPDIR"] = os.getcwd() + "/tmp"
2535
2636
import random2 as random_module
2737
import sys

0 commit comments

Comments
 (0)