A deathtrap is a literary and dramatic plot device in which a villain who has captured the hero or another sympathetic character attempts to use an elaborate, improbable, and usually sadistic method of murdering them.
It may also be a means to show the hero's resourcefulness in escaping, or the writer's ingenuity at devising a last-minute rescue or deus ex machina.
This plot device is generally believed to have been popularized by movie serials and 19th-century theatrical melodramas.
A well-known example is the cliché of the moustache-twirling villain leaving the heroine tied to railroad tracks.
This is echoed in the film 2001 - A Space Odyssey when Hal the supercomputer, confident that Dave will soon perish outside the ship, tells him that he is about to take control of the expedition and then sees Dave off with the flat remark: "This conversation can have no meaningful purpose anymore - goodbye!".