Back in the Middle Ages, when baby pigs were being sold at market, they were often placed in bags so they could not escape. It was from this practice that the term "pig in a poke" came about.
Why were you supposed to never buy "a pig in a poke"? Simple: Because sometimes a cheating merchant would not put a baby piglet in the bag, but instead would substitute a live cat. Foiling this practice is how we got the term "to let the cat out of the bag" and why we caution people to make sure they are never "left holding the bag."