my (limited) understanding is that there is register which has to be set to 0 for 40MHz, or 1 for 26MHz crystals.
the esp8266 library in the arduino ide has a settings (core_esp8266_phy.c, phy_init_data[48])
the espressif flash download tool has a setting too (and a way to auto detect it also)
but I could not find an equivalent option in the cloud build, nor a setting in PyFlasher or esptool.py