It's safe to wash the engine compartment on most vehicles, but you need to be familiar with the layout, be careful, and use common sense.
My truck's owner's manual suggests cleaning the engine and shows parts that should be covered. Personally, I don't cover these parts. Why? I'm lazy about it and they get wet when it rains anyway. I have never had a problem, but I don't hit these parts with a bunch of water either. Basically, avoid spraying anything electrical or that might not be sealed all that well.
I either wash the engine cold, then drive it immediately afterward to dry, or I wash the engine while it's running and go for a drive. Do not wash a hot engine that is turned off.
I have started using a pressure washer. The garden hose works fine, but the pressure washer works better. Just don't do anything stupid with it. If you keep the wand at a reasonable distance and don't blast sensitive components it will be fine.
Use discretion based on the type of vehicle. For example, on a leaky older car or a car with sensitive electronics, I probably wouldn't use the pressure washer.