I can’t run code in codejail sandbox

If I run a python-code (in my python-program, external grader) by command as:

“p = subprocess.Popen([“py.test”, “{0} test FILE_GENERATEED_WITH_CODE_TO_RUN_IN_SANDBOX.py”.format(problem_name[‘problem_name’]), program_name, “-v”], stdout=subprocess.PIPE, stderr=subprocess.PIPE)”

, than a code will be runned out of sandbox, just as in command line: “py.test FILE_GENERATEED_WITH_CODE_TO_RUN_IN_SANDBOX.py”.
But I should and want to run code (which is got from “Problem”-element, code is wrote by student of course) in sandbox, codejail sandbox. How to do it?

I’ve take it from:

File with the code (running code without sandbox) is: PythonGrader.py

Thank you for your many answers…
I cann’t use your program. But it’s OK, normal)

OK, I’ve decided to run code just without codejail sandbox,
But as user without any access rights.
By command:
su username -c ‘python code.py’