{"record":{"id":"e10471602df9c363","repo":"sgl-project/sglang","slug":"command-contains-only-environment-variable-assignm","errorCode":null,"errorMessage":"Command contains only environment variable assignments, no executable","messagePattern":"Command contains only environment variable assignments, no executable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/utils.py","lineNumber":497,"sourceCode":"    Supports leading KEY=VALUE env vars (e.g. \"VAR=1 python script.py\") so that\n    notebook/CI commands work without requiring shell=True.\n    \"\"\"\n    command = command.replace(\"\\\\\\n\", \" \").replace(\"\\\\\", \" \")\n    parts = command.split()\n    env = os.environ.copy()\n    i = 0\n    while i < len(parts):\n        part = parts[i]\n        if \"=\" in part and not part.startswith(\"-\") and not part.startswith(\"/\"):\n            key, _, value = part.partition(\"=\")\n            if key and value is not None and key.replace(\"_\", \"\").isalnum():\n                env[key] = value\n                i += 1\n                continue\n        break\n    parts = parts[i:]\n    if not parts:\n        raise ValueError(\n            \"Command contains only environment variable assignments, no executable\"\n        )\n    return subprocess.Popen(parts, text=True, stderr=subprocess.STDOUT, env=env)\n\n\ndef launch_server_cmd(command: str, host: str = \"0.0.0.0\", port: int = None):\n    \"\"\"\n    Launch the server using the given command.\n    If no port is specified, a free port is reserved.\n    \"\"\"\n    if port is None:\n        port, lock_socket = reserve_port(host)\n    else:\n        lock_socket = None\n\n    full_command = f\"{command} --port {port}\"\n    process = execute_shell_command(full_command)\n","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/utils.py#L479-L515","documentation":"execute_shell_command strips leading KEY=VALUE assignments to build the env; if the command consists ONLY of assignments there is no executable left, so it raises ValueError.","triggerScenarios":"Calling execute_shell_command/launch_server_cmd with a string like 'CUDA_VISIBLE_DEVICES=0 python=...' — actually with only assignments, e.g. 'FOO=1 BAR=2' and nothing after.","commonSituations":"Buggy command construction that appends the executable after a formatting mistake; empty or truncated command strings in test scripts.","solutions":["Fix the command string to include the executable (e.g. 'python -m sglang.launch_server ...')","If you meant env only, add the program explicitly"],"exampleFix":"# before\nlaunch_server_cmd(\"CUDA_VISIBLE_DEVICES=0\")\n# after\nlaunch_server_cmd(\"CUDA_VISIBLE_DEVICES=0 python -m sglang.launch_server ...\")","handlingStrategy":"validation","validationCode":"parts = command.split()\nhas_exec = any(p for p in parts if '=' not in p or parts.index(p) > 0 and '=' in p and False) or len([p for p in parts if not re.match(r'^\\w+=', p)]) > 0","typeGuard":"def has_executable(cmd: str) -> bool:\n    import re\n    return any(not re.match(r'^[A-Za-z_][A-Za-z0-9_]*=', p) for p in cmd.split())","tryCatchPattern":null,"preventionTips":["Always include the executable in command strings","Unit-test command builders that concatenate env + program"],"tags":["shell","subprocess","validation"],"backgroundTag":"missing-executable-in-command","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}