sgl-project/sglang · error · ValueError

Command contains only environment variable assignments, no e

Error message

Command contains only environment variable assignments, no executable

What it means

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.

Source

Thrown at python/sglang/utils.py:497

    Supports leading KEY=VALUE env vars (e.g. "VAR=1 python script.py") so that
    notebook/CI commands work without requiring shell=True.
    """
    command = command.replace("\\\n", " ").replace("\\", " ")
    parts = command.split()
    env = os.environ.copy()
    i = 0
    while i < len(parts):
        part = parts[i]
        if "=" in part and not part.startswith("-") and not part.startswith("/"):
            key, _, value = part.partition("=")
            if key and value is not None and key.replace("_", "").isalnum():
                env[key] = value
                i += 1
                continue
        break
    parts = parts[i:]
    if not parts:
        raise ValueError(
            "Command contains only environment variable assignments, no executable"
        )
    return subprocess.Popen(parts, text=True, stderr=subprocess.STDOUT, env=env)


def launch_server_cmd(command: str, host: str = "0.0.0.0", port: int = None):
    """
    Launch the server using the given command.
    If no port is specified, a free port is reserved.
    """
    if port is None:
        port, lock_socket = reserve_port(host)
    else:
        lock_socket = None

    full_command = f"{command} --port {port}"
    process = execute_shell_command(full_command)

View on GitHub (pinned to 0132848349)

Solutions

  1. Fix the command string to include the executable (e.g. 'python -m sglang.launch_server ...')
  2. If you meant env only, add the program explicitly

Example fix

# before
launch_server_cmd("CUDA_VISIBLE_DEVICES=0")
# after
launch_server_cmd("CUDA_VISIBLE_DEVICES=0 python -m sglang.launch_server ...")
Defensive patterns

Strategy: validation

Validate before calling

parts = command.split()
has_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

Type guard

def has_executable(cmd: str) -> bool:
    import re
    return any(not re.match(r'^[A-Za-z_][A-Za-z0-9_]*=', p) for p in cmd.split())

Prevention

When it happens

Trigger: 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.

Common situations: Buggy command construction that appends the executable after a formatting mistake; empty or truncated command strings in test scripts.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/e10471602df9c363. Report an issue: GitHub.