Spaces:
Running
Running
Commit ·
cc0b899
1
Parent(s): 5aa2260
Update 2026-03-22 09:26:00
Browse files- tools/code_tool.py +9 -6
tools/code_tool.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
-
import io, contextlib
|
| 2 |
|
| 3 |
_SAFE_BUILTINS = {
|
| 4 |
-
k:
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def run_code(code: str) -> str:
|
|
|
|
| 1 |
+
import io, contextlib, builtins
|
| 2 |
|
| 3 |
_SAFE_BUILTINS = {
|
| 4 |
+
k: getattr(builtins, k)
|
| 5 |
+
for k in (
|
| 6 |
+
"print","range","len","sum","max","min","abs","round","sorted",
|
| 7 |
+
"list","dict","set","tuple","str","int","float","bool","enumerate",
|
| 8 |
+
"zip","map","filter","isinstance","type","repr","chr","ord"
|
| 9 |
+
)
|
| 10 |
+
if hasattr(builtins, k)
|
| 11 |
+
}
|
| 12 |
|
| 13 |
|
| 14 |
def run_code(code: str) -> str:
|