Is there a roadside workaround for a freehub that won't engage reliably?
Use strong cable ties or wire/cable to tie the biggest sprocket to the rear wheel spokes. This will eliminate the freewheel, so be very careful when slowing down or going downhill.
If cable ties are too weak, shifting or brake cables should work nicely. If you don’t have any spares you could even scavenge the front derailleur shift cable.
However, I think this problem is best treated with preventive maintenance and should announce itself quite early. If the sound of your freewheel changes or you notice it engaging slowly or failing to engage occasionally you should open it and lube it.