There was a lucky escape for Lewis Hamilton as he managed to stay out of the barriers after spinning off in qualifying at Silverstone.