It's all reasonably straight forward. An air mass travelling towards an obstacle (ie wind blowing on a hill) will be forced over the top of that hill.
If you fly in the area where the air is being forced upwards then you can stay airborne, so long as the air is ascending faster than your aircraft is descending.
Safety margins depend a lot on what you are flying and the shape of the hill. I've managed to stay airborne in a glider in about 5 knots of breeze, blowing straight on to a steep cliff. Also keen in mind that if the wind suddenly stops, the aircraft will still fly, it will just glide down to the ground. In my case (in the video) I am always within range of an airfield, just in case. Top speed on that glider is 300kph, I was doing somewhere between 200 and 250. Lots of fun

There are certainly safety issues. The leeward side of the hill is a dangerous place to be since all that air is coming back down again and can take you down with it. You should also turn away from the hill, as turning towards it can result in you misjudging and getting blown into the side of the hill!
Essay over . . .