1801, "spectre, apparition, ghost," from Dutch spook, from Middle Dutch spooc "spook, ghost," from a common Germanic source (German Spuk "ghost, apparition," Middle Low German spok "spook," Swedish spok "scarecrow," Norwegian spjok "ghost, specter," Danish spøg "joke"), of unknown origin. According to Klein's sources, possible outside connections include Lettish spigana "dragon, witch," spiganis "will o' the wisp," Lithuanian spingu, spingėti "to shine," Old Prussian spanksti "spark."
Meaning "undercover agent" is attested from 1942. The derogatory racial sense of "black person" is attested from 1940s, perhaps from notion of dark skin being difficult to see at night. Black pilots trained at Tuskegee Institute during World War II called themselves the Spookwaffe.