“If there’s a third world war we want to make sure there’s enough of a seed of human civilisation somewhere else to bring it back and shorten the length of the dark ages,” Musk said, responding to questions from his friend Jonah Nolan, the co-creator of the TV show Westworld.

SpaceX is working on a vehicle that will take humans to Mars, a 100-metre ship codenamed the BFR (Big Fucking Rocket). But building a colony would require “tremendous entrepreneurial resources”, Musk said.

He also countered the suggestion that Mars might be “some escape hatch for rich people” by highlighting the risks of the mission: “It will be like Shackleton’s ad for Antarctic explorers: ‘Difficult, dangerous, a good chance you’ll die, excitement for those who survive.’ That kind of thing.

“There’s not many people who will want to go in the beginning,” he said, adding that over time the Red Planet colony would be hospitable and have “great bars. The Mars bar! I love dad jokes, I’m a dad!”

The BFR will fly for the first time in the first half of 2019, Musk said, acknowledging that his “timelines historically have been optimistic”. The production of the Tesla Model 3 electric car, for example, has been plagued by delays.

Musk said he initially gave SpaceX and Tesla a likelihood of success of just 10%.

“I wouldn’t let my friends invest because I didn’t want them to lose their money,” he said of SpaceX. Instead he funnelled his own money, from the sale of PayPal, into the businesses.

“SpaceX is alive by the skin of its teeth. So is Tesla. If things had gone a little bit the other way, both companies would be dead.”

Musk said he was now kept awake at night by the threat posed by unregulated artificial intelligence, which he has previously warned could lead humanity into a third world war – another the reason to go to Mars.

“Mark my words,” he said, “AI is much more dangerous than nukes. So why do we have no regulatory oversight?”

He suggested a public regulatory body would need “insight and oversight” to confirm that everyone was developing AI safely and in a way that is “symbiotic with humanity”.

However, even coming up with the safety parameters would present all sorts of insidious and unexpected risks, Musk said. If the utility function of artificial intelligence is to maximise happiness of humans, a super-intelligent AI might decide that the best way to do that is to capture all humans and inject their brains with dopamine and serotonin.

Musk proposed that digital intelligence should instead be directed to maximise “the freedom of action of humanity”.

The Q&A session ended on a surreal note as Musk, his younger brother Kimbal and Nolan all donned stetsons and sang a snippet of My Little Buttercup, a song from the 1986 movie The Three Amigos.