crewAIInc/crewAI · error · SystemExit

An unexpected error occurred while running the JSON crew: {e

Error message

An unexpected error occurred while running the JSON crew: {e}

What it means

Catch-all around the subprocess that runs a JSON crew (subprocess.run with check=True and a custom env). CalledProcessError is converted to the child's exit code first; this handler fires only for other exceptions — typically OSError/FileNotFoundError when the executable cannot spawn, or KeyboardInterrupt-adjacent failures. The message is echoed (note: to stdout, not err) and the process exits 1.

Source

Thrown at lib/cli/src/crewai_cli/run_crew.py:491

        env[CREWAI_TRAINED_AGENTS_FILE_ENV] = trained_agents_file
    if crew_path is not None:
        env[_CREWAI_JSON_CREW_DEFINITION_ENV] = str(crew_path)
    if inputs is not None:
        env[_CREWAI_JSON_CREW_INPUTS_ENV] = inputs

    try:
        subprocess.run(  # noqa: S603
            command,
            capture_output=False,
            text=True,
            check=True,
            env=env,
        )
    except subprocess.CalledProcessError as e:
        raise SystemExit(e.returncode) from e
    except Exception as e:
        click.echo(f"An unexpected error occurred while running the JSON crew: {e}")
        raise SystemExit(1) from e

    return None


def _chain_deploy() -> None:
    from rich.console import Console

    console = Console()

    def print_system_exit_failure(exc: SystemExit) -> None:
        if isinstance(exc.code, int):
            detail = f" with exit code {exc.code}"
        elif exc.code:
            detail = f": {exc.code}"
        else:
            detail = ""
        console.print(f"\nDeploy failed{detail}\n", style="bold red")

View on GitHub (pinned to 754d7323be)

Solutions

  1. Read the exception text: 'No such file or directory' means the spawn executable is missing — install it or fix PATH.
  2. Ensure the command runs in an environment where the interpreter/runner used for JSON crews is installed and on PATH.
  3. If you pass a custom env to the CLI or wrap it, verify every variable is a string and PATH is preserved.
  4. Since the message goes to stdout, check stdout (not stderr) when scraping CI logs for it.
Defensive patterns

Strategy: try-catch

Validate before calling

import shutil

runner = "uv"  # executable the JSON-crew subprocess invokes
if shutil.which(runner) is None:
    raise SystemExit(f"{runner} missing from PATH; install it before running JSON crews")

Try / catch

try:
    run_json_crew(...)
except SystemExit as e:
    code = e.code
    if code == 1 and spawned_ok is False:
        # distinguish spawn failure (executable missing) from crew failure
        logging.error("JSON crew subprocess failed to start; check PATH/uv")
    raise

Prevention

When it happens

Trigger: The JSON-crew subprocess command references an interpreter/runner not present in env (FileNotFoundError); the constructed `env` dict is invalid (e.g. non-string values) raising TypeError or ValueError; a closed/stdin issue raising OSError.

Common situations: CI images lacking `uv`/`python` on PATH; env manipulation code injecting None or int values into os.environ copies; running with a stripped-down environment (env -i) that loses PATH.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/acd974619b74b37a. Report an issue: GitHub.