At the checkpoint
Officers sometimes ask for food to come out of the bag so the X-ray image is clear.
Flying home from abroad
TSA’s answer covers screening at US airports. On the way home you go through the other airport’s screening first, and its rules are the ones that count there.
Coming home through US customs
CBP says many prepared foods are admissible, and almost anything containing meat is not. Neither CBP nor USDA names snack bars, so the CBP specialist decides.
Declare it either way. USDA says declared food brings no penalty, even when it’s refused. What happens if you don’t.
TSA puts this on every entry: “The final decision rests with the TSA officer on whether an item is allowed through the checkpoint.”