Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
codejail
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
codejail
Commits
543de052
Commit
543de052
authored
Apr 05, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hint functions are now run in the sandbox.
parent
a5d91834
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
codejail/safe_exec.py
+6
-4
No files found.
codejail/safe_exec.py
View file @
543de052
"""Safe execution of untrusted Python code."""
import
json
import
logging
import
os.path
import
shutil
import
sys
...
...
@@ -9,6 +10,8 @@ import textwrap
from
codejail
import
jailpy
from
codejail.util
import
temp_directory
,
change_directory
log
=
logging
.
getLogger
(
__name__
)
def
safe_exec
(
code
,
globals_dict
,
files
=
None
,
python_path
=
None
):
"""Execute code as "exec" does, but safely.
...
...
@@ -78,10 +81,9 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
# Turn this on to see what's being executed.
if
0
:
print
"--{:-<40}"
.
format
(
" jailed "
)
print
jailed_code
print
"--{:-<40}"
.
format
(
" exec "
)
print
code
log
.
debug
(
"Jailed code:
%
s"
,
jailed_code
)
log
.
debug
(
"Exec:
%
s"
,
code
)
log
.
debug
(
"Stdin:
%
s"
,
stdin
)
res
=
jailpy
.
jailpy
(
jailed_code
,
stdin
=
stdin
,
files
=
files
)
if
res
.
status
!=
0
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment