2626
2727
2828class RunCommandToolConfig (BaseModel ):
29- """Config model for RunCommandTool (built from kwargs only, no global section)."""
29+ """Config model for RunCommandTool (built from kwargs only, no global
30+ section)."""
3031
3132 root_path : str | None = None
3233 mode : str = "unsafe"
3334 timeout_seconds : int = DEFAULT_TIMEOUT_SECONDS
3435
3536
3637def _validate_command_paths (command : str , root_path : Path ) -> str | None :
37- """If any path-like token in command escapes root_path, return error message; else None."""
38+ """If any path-like token in command escapes root_path, return error
39+ message; else None."""
3840 try :
3941 parts = shlex .split (command )
4042 except ValueError :
@@ -114,7 +116,8 @@ async def __call__(self, context: AgentContext, config: AgentConfig, **kwargs: A
114116 return await self ._run_unsafe (cfg )
115117
116118 async def _run_safe (self , cfg : RunCommandToolConfig ) -> str :
117- """Execute via bwrap; require bwrap in PATH and return error with install link if missing."""
119+ """Execute via bwrap; require bwrap in PATH and return error with
120+ install link if missing."""
118121 bwrap_path = shutil .which ("bwrap" )
119122 if not bwrap_path :
120123 return (
@@ -138,9 +141,7 @@ async def _run_safe(self, cfg: RunCommandToolConfig) -> str:
138141 logger .exception ("RunCommandTool bwrap exec failed" )
139142 return f"Error: { e !s} "
140143 try :
141- stdout , stderr = await asyncio .wait_for (
142- process .communicate (), timeout = cfg .timeout_seconds
143- )
144+ stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = cfg .timeout_seconds )
144145 except asyncio .TimeoutError :
145146 process .kill ()
146147 await process .wait ()
@@ -150,7 +151,8 @@ async def _run_safe(self, cfg: RunCommandToolConfig) -> str:
150151 return self ._format_result (out , err , process .returncode or 0 )
151152
152153 async def _run_unsafe (self , cfg : RunCommandToolConfig ) -> str :
153- """Execute via OS subprocess with optional root_path as cwd and path validation."""
154+ """Execute via OS subprocess with optional root_path as cwd and path
155+ validation."""
154156 cwd = None
155157 if cfg .root_path :
156158 root = Path (cfg .root_path ).expanduser ().resolve ()
@@ -172,9 +174,7 @@ async def _run_unsafe(self, cfg: RunCommandToolConfig) -> str:
172174 cwd = cwd ,
173175 )
174176 try :
175- stdout , stderr = await asyncio .wait_for (
176- process .communicate (), timeout = cfg .timeout_seconds
177- )
177+ stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = cfg .timeout_seconds )
178178 except asyncio .TimeoutError :
179179 process .kill ()
180180 await process .wait ()
0 commit comments