The actor began improving a song, and soon it morphed into a track for the soundtrack.

Meet Samuel L. Jackson, master lyricist.
The Hitman's Bodyguard is marketed as being a mashup of all the things audiences know and love about the actor (humor, profanity and general badassery), but it turns out it will also feature a new Jackson talent: songwriting.
On Friday, Jackson debuted "Nobody Gets Out Alive," a song he wrote and performed for the film's soundtrack.
"He and Ryan Reynolds were sitting, just the two of them, in his car talking, and he just kind of breaks out into song. I think it was more or less improvised on the set," composer Atli Orvarsson tells Heat Vision.
Director Patrick Hughes recognized Jackson was on to something, and encouraged him to keep working on it, soon sending the idea to his composer to help arrange.
Thus began an international collaboration, with Orvarsson and Jackson sending ideas back and forth, as the composer traveled the world recording different segments in places like London and New York.
The result is a bluesy gospel song that opens with lyrics that are unmistakably Jackson: "Life is a highway, and it's mighty f—ing long."
"It was an international collage," says the composer. "There is a gospel element too. At the end of the day, Samuel Jackson's character is a hitman, but his history, you learn in the film, is very complicated and there's kind of a gospel aspect to his character and his story."
The Hitman's Bodyguard opens Aug. 18.

Here's the track.