Skip to content

Commit dfb3b0f

Browse files
committed
Updates
1 parent d715b1a commit dfb3b0f

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ pip install safeexecute
2121
Set your working directory which is where any potential outputs of the code will be stored. This is also where the code will be executed.
2222

2323
```python
24+
import os
2425
from safeexecute import execute_python_code
2526

2627
working_directory = os.path.join(os.getcwd(), "WORKSPACE")
2728
code = "print('Hello, World!')"
2829

2930
result = execute_python_code(code=code, working_directory=working_directory)
31+
print(result)
3032
```

safeexecute/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def install_docker_image():
1818
return client
1919

2020

21-
async def execute_python_code(code: str, working_directory: str) -> str:
21+
def execute_python_code(code: str, working_directory: str) -> str:
2222
# Create working directory if it doesn't exist
2323
if not os.path.exists(working_directory):
2424
os.makedirs(working_directory)
@@ -57,7 +57,7 @@ async def execute_python_code(code: str, working_directory: str) -> str:
5757
# Run the Python code in the container
5858
container = client.containers.run(
5959
IMAGE_NAME,
60-
f"python {temp_file}",
60+
f"python /workspace/temp.py",
6161
volumes={
6262
os.path.abspath(working_directory): {
6363
"bind": "/workspace",

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.4",
11+
version="0.0.5",
1212
description="Safe way to execute Python code with containerization.",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",

test.ipynb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 10,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Hello, World!\n",
13+
"\n"
14+
]
15+
}
16+
],
17+
"source": [
18+
"import os\n",
19+
"from safeexecute import execute_python_code\n",
20+
"\n",
21+
"working_directory = os.path.join(os.getcwd(), \"WORKSPACE\")\n",
22+
"code = \"print('Hello, World!')\"\n",
23+
"\n",
24+
"result = execute_python_code(code=code, working_directory=working_directory)\n",
25+
"print(result)"
26+
]
27+
}
28+
],
29+
"metadata": {
30+
"kernelspec": {
31+
"display_name": "Python 3",
32+
"language": "python",
33+
"name": "python3"
34+
},
35+
"language_info": {
36+
"codemirror_mode": {
37+
"name": "ipython",
38+
"version": 3
39+
},
40+
"file_extension": ".py",
41+
"mimetype": "text/x-python",
42+
"name": "python",
43+
"nbconvert_exporter": "python",
44+
"pygments_lexer": "ipython3",
45+
"version": "3.10.12"
46+
},
47+
"orig_nbformat": 4
48+
},
49+
"nbformat": 4,
50+
"nbformat_minor": 2
51+
}

0 commit comments

Comments
 (0)