| import asyncio |
| import shlex |
| from typing import List, Tuple |
|
|
|
|
| from autogen_core import CancellationToken |
| from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor |
|
|
|
|
| async def exec_command_umask_patched( |
| self: DockerCommandLineCodeExecutor, |
| command: List[str], |
| cancellation_token: CancellationToken, |
| ) -> Tuple[str, int]: |
| if self._container is None or not self._running: |
| raise ValueError( |
| "Container is not running. Must first be started with either start or a context manager." |
| ) |
|
|
| |
| joined = shlex.join(command) |
| shell_cmd = f"umask 000 && {joined}" |
| command = ["sh", "-c", shell_cmd] |
|
|
| exec_task = asyncio.create_task( |
| asyncio.to_thread(self._container.exec_run, command) |
| ) |
| cancellation_token.link_future(exec_task) |
|
|
| |
| try: |
| result = await exec_task |
| exit_code = result.exit_code |
| output = result.output.decode("utf-8") |
| if exit_code == 124: |
| output += "\n Timeout" |
| return output, exit_code |
| except asyncio.CancelledError: |
| |
| self._cancellation_tasks.append( |
| asyncio.create_task(self._kill_running_command(command)) |
| ) |
| return "Code execution was cancelled.", 1 |
|
|