@@ -197,14 +197,16 @@ def __init__(
197197 tool_names : list [str ],
198198 agent : "SerenaAgent" ,
199199 tool_usage_stats : ToolUsageStats | None = None ,
200+ host : str = "127.0.0.1" ,
200201 ) -> None :
201202 self ._memory_log_handler = memory_log_handler
202203 self ._tool_names = tool_names
203204 self ._agent = agent
205+ self ._host = host
204206 self ._app = Flask (__name__ )
205-
206- self ._app . config [ "TRUSTED_HOSTS" ] = [ "127.0.0.1" , "localhost" ]
207-
207+ local_hosts = [ "127.0.0.1" , "localhost" ]
208+ if self ._host in local_hosts :
209+ self . _app . config [ "TRUSTED_HOSTS" ] = local_hosts
208210 self ._tool_usage_stats = tool_usage_stats
209211 self ._loaded_news : dict [str , str ] = {}
210212 self ._news_ready = threading .Event ()
@@ -770,21 +772,21 @@ def _find_first_free_port(start_port: int, host: str) -> int:
770772
771773 raise RuntimeError (f"No free ports found starting from { start_port } " )
772774
773- def run (self , host : str , port : int ) -> int :
775+ def run (self , port : int ) -> int :
774776 """
775777 Runs the dashboard on the given host and port and returns the port number.
776778 """
777779 # patch flask.cli.show_server to avoid printing the server info
778780 from flask import cli
779781
780782 cli .show_server_banner = lambda * args , ** kwargs : None
781- self ._app .run (host = host , port = port , debug = False , use_reloader = False , threaded = True )
783+ self ._app .run (host = self . _host , port = port , debug = False , use_reloader = False , threaded = True )
782784 return port
783785
784- def run_in_thread (self , host : str ) -> tuple [threading .Thread , int ]:
785- port = self ._find_first_free_port (self .BASE_PORT , host )
786- log .info ("Starting dashboard (listen_address=%s, port=%d)" , host , port )
787- thread = threading .Thread (target = lambda : self .run (host = host , port = port ), daemon = True )
786+ def run_in_thread (self ) -> tuple [threading .Thread , int ]:
787+ port = self ._find_first_free_port (self .BASE_PORT , self . _host )
788+ log .info ("Starting dashboard (listen_address=%s, port=%d)" , self . _host , port )
789+ thread = threading .Thread (target = lambda : self .run (port = port ), daemon = True )
788790 thread .start ()
789791 return thread , port
790792
0 commit comments