I have a Bakflip Mx4 hard tri-fold tonneau to secure things in the bed and prevent groceries from getting wet. I also use a cargo net to prevent bags from spilling:
Bungee Net Holder with Hooks by Delta Cycle, Black - Expandable Cargo Net Keeps Your Gear Tightly in Place for Bikes & Bicycles - Stretches 2X in Size - for Bags, Backpack or Motorcycle Helmet