{"record":{"id":"9aa0f18a0697c02d","repo":"microsoft/autogen","slug":"powershell-or-pwsh-is-not-installed-please-instal","errorCode":null,"errorMessage":"Powershell or pwsh is not installed. Please install one of them.","messagePattern":"Powershell or pwsh is not installed\\. Please install one of them\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py","lineNumber":169,"sourceCode":"\nPYTHON_VARIANTS = [\"python\", \"Python\", \"py\"]\n\n\ndef lang_to_cmd(lang: str) -> str:\n    if lang in PYTHON_VARIANTS:\n        return \"python\"\n    if lang.startswith(\"python\") or lang in [\"bash\", \"sh\"]:\n        return lang\n    if lang in [\"shell\"]:\n        return \"sh\"\n    if lang in [\"pwsh\", \"powershell\", \"ps1\"]:\n        # Check if pwsh is available, otherwise fall back to powershell\n        if shutil.which(\"pwsh\") is not None:\n            return \"pwsh\"\n        elif shutil.which(\"powershell\") is not None:\n            return \"powershell\"\n        else:\n            raise ValueError(\"Powershell or pwsh is not installed. Please install one of them.\")\n    else:\n        raise ValueError(f\"Unsupported language: {lang}\")\n\n\n# Regular expression for finding a code block\n# ```[ \\t]*(\\w+)?[ \\t]*\\r?\\n(.*?)[ \\t]*\\r?\\n``` Matches multi-line code blocks.\n#   The [ \\t]* matches the potential spaces before language name.\n#   The (\\w+)? matches the language, where the ? indicates it is optional.\n#   The [ \\t]* matches the potential spaces (not newlines) after language name.\n#   The \\r?\\n makes sure there is a linebreak after ```.\n#   The (.*?) matches the code itself (non-greedy).\n#   The \\r?\\n makes sure there is a linebreak before ```.\n#   The [ \\t]* matches the potential spaces before closing ``` (the spec allows indentation).\nCODE_BLOCK_PATTERN = r\"```[ \\t]*(\\w+)?[ \\t]*\\r?\\n(.*?)\\r?\\n[ \\t]*```\"\n\n\ndef infer_lang(code: str) -> str:\n    \"\"\"infer the language for the code.","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/_common.py#L151-L187","documentation":"The code-block language normalizer in autogen_ext.code_executors._common maps 'pwsh', 'powershell', and 'ps1' to an actual PowerShell binary by probing PATH with shutil.which — first pwsh (PowerShell 7+), then the Windows-only powershell. If neither is found it raises ValueError telling you to install one. This is an environment requirement, not a code bug: executing PowerShell blocks requires a PowerShell runtime.","triggerScenarios":"An LLM emits a ```powershell code block that reaches LocalCommandLineCodeExecutor (or similar) on a Linux/macOS box or container where pwsh was never installed.","commonSituations":"Linux Docker images (python:*-slim, distroless) without PowerShell, macOS without brew install powershell, CI runners where only bash exists, agents prompted for Windows-style commands.","solutions":["Install PowerShell 7: on Debian/Ubuntu follow Microsoft's install (or brew install --cask powershell on macOS); verify with pwsh --version","In Docker: RUN apt-get update && apt-get install -y powershell (from the MS repo) or use the mcr.microsoft.com/powershell base image","Prompt the model to emit bash/sh or python code blocks instead of PowerShell","As a last resort, treat the error as a signal to rerun the block translated to python"],"exampleFix":"# before (Dockerfile)\nFROM python:3.12-slim\nRUN pip install autogen-ext\n# powershell blocks fail: ValueError\n\n# after\nFROM python:3.12-slim\nRUN wget -q https://github.com/PowerShell/PowerShell/releases/download/v7.4.6/powershell-7.4.6-linux-x64.tar.gz \\\n    && tar -xzf powershell-7.4.6-linux-x64.tar.gz -C /usr/local/pwsh \\\n    && ln -s /usr/local/pwsh/pwsh /usr/local/bin/pwsh","handlingStrategy":"fallback","validationCode":"import shutil\ndef powershell_available() -> bool:\n    return shutil.which('pwsh') is not None or shutil.which('powershell') is not None","typeGuard":null,"tryCatchPattern":"try:\n    result = await executor.execute_code(blocks, token)\nexcept ValueError as e:\n    if 'Powershell or pwsh' in str(e):\n        blocks = [b for b in blocks if b.language not in ('pwsh', 'powershell', 'ps1')]\n        result = await executor.execute_code(blocks, token)  # skip ps blocks\n    else:\n        raise","preventionTips":["Bake pwsh into execution images at build time","Constrain model prompts to python/bash code blocks on Linux hosts","Fail fast at startup with a which('pwsh') check if PowerShell blocks are expected"],"tags":["powershell","code-executor","environment","dependency"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}