Spaces:
Sleeping
Sleeping
Sw1ft0
commited on
Commit
·
1f650a0
1
Parent(s):
7f64dba
Add a restricted set of built-ins
Browse files
app.py
CHANGED
|
@@ -124,8 +124,29 @@ Rules:
|
|
| 124 |
# Prepare sandbox
|
| 125 |
local_vars = {"df1": df1, "df2": df2, "pd": pd}
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
# Execute code
|
| 128 |
-
exec(safe_code, {"__builtins__":
|
| 129 |
|
| 130 |
# Fetch result
|
| 131 |
result = local_vars.get("result", "No result produced")
|
|
|
|
| 124 |
# Prepare sandbox
|
| 125 |
local_vars = {"df1": df1, "df2": df2, "pd": pd}
|
| 126 |
|
| 127 |
+
# Define a restricted set of built-ins
|
| 128 |
+
safe_builtins = {
|
| 129 |
+
"abs": abs,
|
| 130 |
+
"all": all,
|
| 131 |
+
"any": any,
|
| 132 |
+
"bool": bool,
|
| 133 |
+
"dict": dict,
|
| 134 |
+
"float": float,
|
| 135 |
+
"int": int,
|
| 136 |
+
"len": len,
|
| 137 |
+
"list": list,
|
| 138 |
+
"max": max,
|
| 139 |
+
"min": min,
|
| 140 |
+
"range": range,
|
| 141 |
+
"str": str,
|
| 142 |
+
"sum": sum,
|
| 143 |
+
"round": round,
|
| 144 |
+
"KeyError": KeyError,
|
| 145 |
+
"ValueError": ValueError,
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
# Execute code
|
| 149 |
+
exec(safe_code, {"__builtins__": safe_builtins}, local_vars)
|
| 150 |
|
| 151 |
# Fetch result
|
| 152 |
result = local_vars.get("result", "No result produced")
|