When Lorene Scafaria sold her pitch for “Seeking a Friend for the End of the World” to Mandate in 2008, she had one stipulation: The buyers had to agree to let her make her directorial debut with the film.

It was quite a request from a writer with only one produced feature to her name, “Nick and Nora’s Infinite Playlist” (2008), and a handful of spec sales and assignments. But even with the deal in her pocket, she knew it was no guarantee she’d actually get to helm the film.

“I don’t think anyone would’ve gotten rid of me,” she says. “It was more a matter of getting a cast to approve of me as a first-time director, and be interested enough in the script to do it for very little money.”

So it was no small thing when Scafaria met with Steve Carell in early 2011 to talk about him playing the film’s lead character, Dodge, a meek man who, faced with the Earth’s imminent destruction, boldly embarks on a road trip to find his high school sweetheart, accompanied by his free-spirited neighbor, Penny.

As she developed the film, Scafaria would call on friends and family to ask how they’d spend the end of days.

Her meeting with Carell took a similar turn. “We got personal right away,” Scafaria says. “He talked about his brothers and his parents, and I talked about my father who had passed. He had incredible insight into (the idea).”

Carell committed to make “Seeking a Friend” his first post-“Office” role, which gave Scafaria the juice to land Keira Knightley for the role of Penny — along with additional financing from Indian Paintbrush. Focus Features distributes.

Scafaria says she felt very calm on the set, though she does relate that the relative scarcity of women in the job produced a few small obstacles. “There were a couple of days when security didn’t believe I was the director,” she laughs.