I have seen videos of red hot jet engines being tested at sea level in a building. But even in a building the temperature difference between the engine and the room is large. Most materials would crack under this temperature gradient particularly with the vibration of the engine.
Just because a temperature difference exist between a material and ambient, does not mean there is a large temperature gradient within the material. Air is an excellent insulator.
Cracking is a function of design and material. By using materials with a low coefficient of thermal expansion and high yield strength, ductile yield behaviour, and good thermal conductivity, you can prevent material from cracking. Additionally, the geometric design of the engine makes sure stress concentrations are avoided from both mechanical and thermal loading.
Why doesn't a hot jet engine crack at 10,000 metres and -50 C air temperature?
Because it's designed not to.
Most materials would crack under this temperature gradient particularly with the vibration of the engine
Jet engines are not made from "most materials".
Short explanation: It's not uncommon to see ITT (internal turbine temperatures) reach 1000 degrees on startup and cruise is a bit cooler. The difference between room temperature and -50 is negligible on such a scale. By the time the intake air is compressed it can be over 400 degrees, and that compression happens gradually along many stages.
Long explanation: The air in a turbine typically reaches over 400F just from the intake/compression stage, that is before any fuel is injected and burned which occurs in the next stage, the combustor.
In the combustor fuel is mixed with part of that hot, high-pressure intake air and burned, and part of the air bypasses the fuel nozzles and is vented back into the combustor to generate a kind of air-cushion between the flame and the combustor walls because they would otherwise melt.
By the time the air reaches the outlet of the combustor it is typically around or below 1000 degrees, and it then enters the exhaust stage(s) which extract energy from this hot, high-velocity, high-pressure air to spin the intake stage and a fan or turboshaft. The turbine blades in modern engines are also typically cooled with bleed air from the intake stage. An afterburner uses the same cooling strategy as the combustor, except the "cooling air" is part of the nearly 1000 degree exhaust air that wasn't mixed with fuel so it can provide a layer of air between the flame and metal surface.
That's a very simplified overview, but I think you can see the idea that turbines are engineered to manage temperatures quite effectively, mostly through use of the hot bleed air from the intake stage.