Safety Cars and VSC's are an almost random variable and you can't completely negate it's effect on a race with rules this is just how racing works, however there could be ways to lessen their effect and often pot-luck nature. I don't have all the answers just some nuggets of thought, I often hear from some people saying when this happens it is a bit of a put off for any fans who are wanting to get into the sport and see the pot-luck nature as unfair and lacks competitive integrity, most F1 fans will argue over the course of a season that luck will even out.
-Introduce a Minimum Pit stop time under VSC's and Safety car
Either a standard fixed time or varying determined on circuit, teams can service their cars but have to spend x amount of time stationary. The benefit being that this would be a pretty straight forward rule to enforce, it could lead to more penalties, but will also disadvantage any teams wanting to double stack perhaps this can be negated if a driver is -5 seconds behind his teamate on the last sector before the safety car and that teamate pits the teamate behind can serve a regular untimed pitstop.
-Pitlane closure until Lead driver passes Sector 3
The whereabouts of cars on circuit is another random potluck variable that is inherent to Safety Cars, maybe if the pitlane is closed until the leader passes sector this will lessen that the benefit being this give more advantage to the driver who has already earned a lead.
Again this may have caveats with drivers on long stints vs cars that have just pitted but these are just thoughts and won't be flawless but with tweaks could help sure up the sports dice roll disadvantages when it comes to safety cars, Thoughts?