title: How can i accept and run user's code securely on my web app?
body: <p>I am working on a django based web app that takes python file as input which contains some function, then in backend i have some lists that are passed as parameters through the user's function,which will generate a single value output.The result generated will be used for some further computation.</p>
  <p>Here is how the function inside the user's file look like :</p>
  <pre><code>def somefunctionname(list):
  
      ''' some computation performed on list'''
  
      return float value
  </code></pre>
  <p>At present the approach that i am using is taking user's file as normal file input. Then in my views.py i am executing the file as module and passing the parameters with eval function. Snippet is given below.</p>
  <p>Here modulename is the python file name that i had taken from user and importing as module</p>
  <pre><code>exec(&quot;import &quot;+modulename)
  
  result = eval(f&quot;{modulename}.{somefunctionname}(arguments)&quot;)
  </code></pre>
  <p>Which is working absolutely fine. But i know this is not the secured approach.</p>
  <p>My question , Is there any other way through which i can run users file securely as the method that i am using is not secure ? I know the proposed solutions can't be full proof but what are the other ways in which i can run this (like if it can be solved with dockerization then what will be the approach or some external tools that i can use with API )?
  Or if possible can somebody tell me how can i simply sandbox this or any tutorial that can help me..?</p>
  <p>Any reference or resource will be helpful.</p>