Skip to content

Commit e88c712

Browse files
author
Cliff Dyer
authored
Merge pull request #47 from edx/cdyer/multijail
Restructure codejail to allow more flexible jailing
2 parents 1903bc9 + 4a9e7c9 commit e88c712

18 files changed

+865
-487
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ James Tauber <[email protected]>
66
Piotr Mitros <[email protected]>
77
Feanil Patel <[email protected]>
88
Dave St.Germain <[email protected]>
9+
Cliff Dyer <[email protected]>

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CodeJail
22

3-
Copyright 2013-2015, edX
3+
Copyright 2013-2016, edX
44

55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this work except in compliance with the License.

README.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ To secure Python execution, you'll be creating a new virtualenv. This means
6161
you'll have two: the main virtualenv for your project, and the new one for
6262
sandboxed Python code.
6363

64-
Choose a place for the new virtualenv, call it **<SANDENV>**. It will be
65-
automatically detected and used if you put it right alongside your existing
66-
virtualenv, but with `-sandbox` appended. So if your existing virtualenv is in
67-
`/home/chris/ve/myproj`, make **<SANDENV>** be `/home/chris/ve/myproj-sandbox`.
64+
Choose a place for the new virtualenv, call it **<SANDENV>**.
6865

6966
The user running the LMS is **<SANDBOX_CALLER>**, for example, you on
7067
your dev machine, or `www-data` on a server.

codejail/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Primary codejail exports.
3+
4+
import codejail
5+
codejail.configure('python78', '/path/to/python3', user='root', lang=codejail.python3)
6+
try:
7+
jail = codejail.get_codejail('python78')
8+
except JailError:
9+
raise
10+
try:
11+
jail.safe_exec("print('foo')", {'print': print}, slug='hotcode')
12+
except codejail.CodeJailException:
13+
# raises a JailError if the jail can't handle safe_exec.
14+
# raises a SafeExecException if the code fails.
15+
raise
16+
jail.jail_code("print('foo')", slug='hotcode')
17+
"""
18+
19+
from .exceptions import CodeJailException, JailError, SafeExecException
20+
from .jail import configure, is_configured, get_codejail
21+
from .languages import python2, python3, other

codejail/django_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.core.exceptions import MiddlewareNotUsed
88
from django.conf import settings
99

10-
import codejail.jail_code
10+
import codejail.limits
1111

1212

1313
class ConfigureCodeJailMiddleware(object):
@@ -27,6 +27,6 @@ def __init__(self):
2727

2828
limits = settings.CODE_JAIL.get('limits', {})
2929
for name, value in limits.items():
30-
codejail.jail_code.set_limit(name, value)
30+
codejail.limits.set_limit(name, value)
3131

3232
raise MiddlewareNotUsed

codejail/exceptions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Codejail exceptions.
3+
"""
4+
5+
6+
class CodeJailException(Exception):
7+
"""
8+
Top of the hierarchy of codejail exceptions
9+
"""
10+
pass
11+
12+
13+
class JailError(CodeJailException):
14+
"""
15+
There was a problem configuring a codejail or accessing a configured codejail.
16+
"""
17+
pass
18+
19+
20+
class SafeExecException(CodeJailException):
21+
"""
22+
Python code running in the sandbox has failed.
23+
24+
The message will be the stdout of the sandboxed process, which will usually
25+
contain the original exception message.
26+
27+
"""
28+
pass

0 commit comments

Comments
 (0)