Water would indeed boil spontaneously in a vacuum, like that found on the surface of the Moon, due to the lack of atmospheric pressure. However, cooking an egg in this environment presents a unique challenge.
When you boil water, it needs to be at a sufficient temperature to cook the food. On Earth, we usually cook eggs in boiling water at 100 degrees Celsius (212 degrees Fahrenheit). But in a vacuum, water will boil at much lower temperatures — around 0 degrees Celsius (32 degrees Fahrenheit) at sea level pressure is where water starts to vaporize, which means it doesn’t reach the high temperature needed for cooking.
As a result, when exposed to the vacuum of space, any water you might have would boil away quickly, and it would never reach the temperatures required to properly cook the egg. Instead, the egg would just become cold and possibly freeze, rather than cooking it as you would on Earth.
In summary, while water can boil in a vacuum, it won’t reach the necessary temperature to cook an egg, making it impractical to do so on the Moon.