Skip to content

Commit 343ebe5

Browse files
committed
Accomodate running in container
1 parent 12bc539 commit 343ebe5

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ You can pass an entire message from a langauge model into the `code` field and i
3535
from safeexecute import execute_python_code
3636

3737
code = "print('Hello, World!')"
38-
3938
result = execute_python_code(code=code)
4039
print(result)
4140
```

safeexecute/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def install_docker_image():
2121
def execute_python_code(code: str, working_directory: str = None) -> str:
2222
if working_directory is None:
2323
working_directory = os.path.join(os.getcwd(), "WORKSPACE")
24+
docker_working_dir = working_directory
25+
if os.environ.get("DOCKER_CONTAINER", False):
26+
docker_working_dir = os.environ.get("WORKING_DIRECTORY", working_directory)
2427
if not os.path.exists(working_directory):
2528
os.makedirs(working_directory)
2629
# Check if there are any package requirements in the code to install
@@ -43,7 +46,7 @@ def execute_python_code(code: str, working_directory: str = None) -> str:
4346
IMAGE_NAME,
4447
f"pip install {package}",
4548
volumes={
46-
os.path.abspath(working_directory): {
49+
os.path.abspath(docker_working_dir): {
4750
"bind": "/workspace",
4851
"mode": "rw",
4952
}
@@ -61,7 +64,7 @@ def execute_python_code(code: str, working_directory: str = None) -> str:
6164
IMAGE_NAME,
6265
f"python /workspace/temp.py",
6366
volumes={
64-
os.path.abspath(working_directory): {
67+
os.path.abspath(docker_working_dir): {
6568
"bind": "/workspace",
6669
"mode": "rw",
6770
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="safeexecute",
11-
version="0.0.8",
11+
version="0.0.9",
1212
description="Safe way to execute Python code with containerization.",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)