Python exec user code on server - os command injection

Viewed 32

I have a project where a user can provide a python script that will be execute on the server to verify if the script is valid according to some criteria. I use the exec function to execute the code but it's vulnerable. User can use the os module in the script.

Is there a way to prevent command injection ? By preventing some modules to be used in exec ? Or another way to execute python code without risking injections ?

Thanks !

0 Answers
Related