There may be ways to avoid some of the other types of accidents, but those ones (which have happened several times) are difficult to escape.
The real question is what's the safety threshold - safer than median human? 90th percentile? 99th?
The same way defensive (human) drivers have been doing for a long time: leave room between you and the car in front of you. Gauge cars coming up behind you and roll forward if they need extra room to stop.
Does not prevent 100% of rear-endings, but a large portion of them. Most rear-enders are not cars plowing full-speed into you, it's someone misjudging their braking and not being fully at-rest when they needed to be. Leaving some margin for this kind of error helps avoid the whole incident.