We now consider this proverb to be a cautionary warning against falling into bad company. In 14th century England, which is when and where this originated, people had a real and everyday fear of the devil, who was believed to be a tangible physical entity capable of corrupting and tricking humans into wicked ways. For them, ‘supping with the devil’ wasn’t a metaphor as we would now understand it but an actual possibility.
The first form of the proverb that I know of is found in Geoffrey Chaucer’s Squire’s Tale, 1390:
Therfore bihoueth hire a ful long spoon That shal ete with a feend.
[Therefore, whoever would eat with a fiend must have a very long spoon.]
The expression was recorded later in Erasmus’ collection of proverbs – Adages, 1545:
He had nede to haue a longe spone that shuld eate with the deuyl.
See also: the List of Proverbs.