Food taken on or off the ship must be commercially packaged and factory sealed. It cannot be in an opened container/package.
It cannot be homemade. It cannot be perishable. So no homemade PB sandwich.
When coming OFF the ship either at a port or at the the end of the trip it also has to meet the applicable customs and agriculture regulations of that country, which generally at least means no fresh fruit or vegetables and usually no meat or dairy. There may be additional restrictions, including country of origin, etc.
Some ports do not allow any food off at all.
If the end of the trip is a US port, such as Port Canaveral, you are strongly encouraged to not bring off any food. However, if you need to, any and all food you bring off MUST be fully declared on the customs form/to the customs agent. There are significant penalties for failing to declare. If you do declare and they decide something is not allowed, they can seize/confiscate it [but since you declared it, no penalty for failing to declare]. In addition to the normal customs officer they may have you speak with the agriculture specialist -- in our experience this adds just a couple minutes to clearing US Customs. We find it helps to create a separate detailed written list of all the food we have and then we can hand that with the customs form to the customs officer [we have food allergies and inevitably will have some leftover safe snacks that we are bringing back off the ship for the rest of our trip which will be a few days at WDW].
FWIW, US CBP has previously advised us to bring the receipts with us for the foods, so we can prove they were bought in the US/Canada. I've never been asked for them, but did have them. We are very clear when we give the verbal explanation that they are foods we brought onto the ship with us at the start of the cruise. We do not buy foods at ports and we do not bring food from the ship itself off at the end of the cruise.
SW