Wilder recruited crime novelist Raymond Chandler to help him adapt James M. Cain's 1943 novel Double Indemnity into a marketable Hollywood feature. Cain based his novel on a notorious 1927 murder trial he covered as a journalist and which was sensationalized in William Randolph Hearst's presses. A woman named Ruth Snyder and her lover were convicted of murder in a plot identical to Walter and Phyllis's double indemnity scheme after turning on each other in court, and sentenced to death by electrocution at New York's Sing Sing prison. The initial ending to Wilder's film featured Walter Neff being executed in a similar manner, but Paramount decided this ending would be too intense for audiences.
Wilder and Chandler's script challenged the limits of the Hays Office, which censored and regulated the motion picture industry between 1930 and 1968. Cain's novel had in fact already made the rounds in Hollywood as a candidate for adaptation before the Hays Office scared off studio interest by issuing a memo decrying the story as too "low" and "sordid" for general audiences. After the story resurfaced, the Hays Office required Wilder and Chandler to make several changes—namely, reducing the explicitness of Phyllis's wardrobe, toning down the scene in which the couple disposes of Mr. Dietrichson's body, and removing Walter's execution scene altogether.
Wilder clashed during the adaptation process with Chandler, who was not an experienced Hollywood screenwriter but had a gifted ear for dialogue. Chandler was also an alcoholic who suffered a relapse while working on the treatment of Cain's novel, which led Wilder to decide to make The Lost Weekend the following year (a story about an alcoholic writer who descends into delirium). Wilder's casting choices were unorthodox: Fred MacMurray was mostly known for playing lighter comic roles, and openly questioned Wilder's judgment in choosing him to play the corrupt, dissolute Walter Neff. Barbara Stanwyck was then the highest paid actress in Hollywood, known for playing strong-willed, virtuous female leads rather than conniving villains.
Wilder was nominated for an Academy Award for Best Director—one of a whopping twenty-one nominations he garnered across several categories over the course of his career. Cain praised Wilder and Chandler's adaptation, in particular the use of the dictaphone as a narrative framing device. Walter Neff's hard-boiled voice-over narration, the film's suspenseful flashback structure, and Stanwyck's sultry performance have all become iconic staples representing the pinnacle of film noir genre. The American Film Industry put Phyllis Dietrichson in the #8 spot on its list of Hollywood's most memorable on-screen villains.