4242USER = os .environ .get ("PYTHON_RUNNER_USER" , "" )
4343GROUP = os .environ .get ("PYTHON_RUNNER_GROUP" , "" )
4444NETWORK = os .environ .get ("PYTHON_RUNNER_NETWORK" , "runner-net" )
45+ READ_ONLY_FILESYSTEM = os .environ .get ('PYTHON_RUNNER_READ_ONLY_FILESYSTEM' , 'false' ).lower () == 'true'
46+ # 100MB by default
47+ TMPFS_MOUNT_SIZE_IN_BYTES = os .environ .get ('PYTHON_RUNNER_TMPFS_MOUNT_SIZE_IN_BYTES' , '104857600' )
4548OTHER_OPTIONS = os .environ .get ("PYTHON_RUNNER_OTHER_OPTIONS" , "[]" )
4649try :
4750 OTHER_OPTIONS = ast .literal_eval (OTHER_OPTIONS )
@@ -272,7 +275,6 @@ def run_python(data):
272275 "--network" ,
273276 NETWORK ,
274277 ]
275- logging .debug ("command: %s" , command )
276278
277279 # timezone, if not set TIME_ZONE in settings then set time zone use timezone_command
278280 if timezone_command :
@@ -296,6 +298,10 @@ def run_python(data):
296298 user_operation += ":" + str (GID )
297299 if user_operation :
298300 command .extend (["-u" , user_operation ])
301+ if READ_ONLY_FILESYSTEM :
302+ command .append ("--read-only" )
303+ # Add tmpfs mount for /tmp (100MB)
304+ command .extend (["--mount" , f"type=tmpfs,dst=/tmp,tmpfs-size={ TMPFS_MOUNT_SIZE_IN_BYTES } " ])
299305 # other options, these options are experimental, may cause failure to start script
300306 if OTHER_OPTIONS and isinstance (OTHER_OPTIONS , list ):
301307 for option in OTHER_OPTIONS :
@@ -310,6 +316,7 @@ def run_python(data):
310316 logging .debug ("try to execute this python runner image: %s" , PYTHON_RUNNER_IMAGE )
311317 command .append (PYTHON_RUNNER_IMAGE )
312318 command .append ("run" ) # override command
319+ logging .debug ("command: %s" , command )
313320
314321 start_at = time .time ()
315322
0 commit comments