Skip to content

Commit 9814b58

Browse files
committed
Add host option and refactor Z3 execution globals
Added a --host argument to server.py to allow specifying the server bind address. Refactored z3_solver.py to rename and clarify the globals preparation function, improving documentation and variable naming for code execution context.
1 parent 93e1b52 commit 9814b58

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

optillm/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ def parse_args():
987987
("--rstar-c", "OPTILLM_RSTAR_C", float, 1.4, "Exploration constant for rStar algorithm"),
988988
("--n", "OPTILLM_N", int, 1, "Number of final responses to be returned"),
989989
("--return-full-response", "OPTILLM_RETURN_FULL_RESPONSE", bool, False, "Return the full response including the CoT with <thinking> tags"),
990+
("--host", "OPTILLM_HOST", str, "127.0.0.1", "Host address to bind the server to (use 0.0.0.0 to allow external connections)"),
990991
("--port", "OPTILLM_PORT", int, 8000, "Specify the port to run the proxy"),
991992
("--log", "OPTILLM_LOG", str, "info", "Specify the logging level", list(logging_levels.keys())),
992993
("--launch-gui", "OPTILLM_LAUNCH_GUI", bool, False, "Launch a Gradio chat interface"),

optillm/z3_solver.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@
1515
class TimeoutException(Exception):
1616
pass
1717

18-
def prepare_safe_globals():
19-
safe_globals = {
18+
def prepare_execution_globals():
19+
"""
20+
Prepare globals dictionary for Z3/SymPy code execution.
21+
22+
WARNING: This is NOT a security sandbox. The name "execution_globals" reflects
23+
that this simply provides the execution environment for solver code, not a
24+
security boundary. The code is executed via exec() with access to z3, sympy,
25+
and math libraries. Only execute trusted code.
26+
"""
27+
execution_globals = {
2028
'print': print,
2129
'__builtins__': {
2230
'True': True,
@@ -35,7 +43,7 @@ def prepare_safe_globals():
3543
}
3644

3745
# Add common math functions
38-
safe_globals.update({
46+
execution_globals.update({
3947
'log': math.log,
4048
'log2': math.log2,
4149
'sqrt': math.sqrt,
@@ -48,10 +56,10 @@ def prepare_safe_globals():
4856
})
4957

5058
# Add complex number support
51-
safe_globals['I'] = complex(0, 1)
52-
safe_globals['Complex'] = complex
59+
execution_globals['I'] = complex(0, 1)
60+
execution_globals['Complex'] = complex
5361

54-
return safe_globals
62+
return execution_globals
5563

5664
def execute_code_in_process(code: str):
5765
import z3
@@ -60,18 +68,18 @@ def execute_code_in_process(code: str):
6068
import itertools
6169
from fractions import Fraction
6270

63-
safe_globals = prepare_safe_globals()
64-
71+
execution_globals = prepare_execution_globals()
72+
6573
# Add Z3 specific functions
6674
z3_whitelist = set(dir(z3))
67-
safe_globals.update({name: getattr(z3, name) for name in z3_whitelist})
75+
execution_globals.update({name: getattr(z3, name) for name in z3_whitelist})
6876

6977
# Add SymPy specific functions
7078
sympy_whitelist = set(dir(sympy))
71-
safe_globals.update({name: getattr(sympy, name) for name in sympy_whitelist})
79+
execution_globals.update({name: getattr(sympy, name) for name in sympy_whitelist})
7280

7381
# Ensure key Z3 and SymPy components are available
74-
safe_globals.update({
82+
execution_globals.update({
7583
'z3': z3,
7684
'sympy': sympy,
7785
'Solver': z3.Solver,
@@ -112,22 +120,22 @@ def as_numerical(x):
112120
return x.approx(20)
113121
return float(x)
114122

115-
safe_globals['as_numerical'] = as_numerical
123+
execution_globals['as_numerical'] = as_numerical
116124

117125
def Mod(x, y):
118126
return x % y
119127

120-
safe_globals['Mod'] = Mod
128+
execution_globals['Mod'] = Mod
121129

122130
def Rational(numerator, denominator=1):
123131
return z3.Real(str(Fraction(numerator, denominator)))
124132

125-
safe_globals['Rational'] = Rational
133+
execution_globals['Rational'] = Rational
126134

127135
output_buffer = io.StringIO()
128136
with contextlib.redirect_stdout(output_buffer):
129137
try:
130-
exec(code, safe_globals, {})
138+
exec(code, execution_globals, {})
131139
except Exception:
132140
return ("error", traceback.format_exc())
133141
return ("success", output_buffer.getvalue())

0 commit comments

Comments
 (0)