What can I do wood before and after finishing a project to ensure that it is very clean and as safe as possible?
Plane or mill or sand through until you're in the fresh wood underneath the surface. That's about it, although you can scrub the wood down prior to this (ideally outside) if it's obviously dirty.
Some woods inherently are a bit of a problem here since they can themselves be a source of potential irritants (not everyone reacts, or to the same degree) or allergens (obviously ditto).
But wood can by and large be considered sterile beneath the surface as long as it doesn't have holes or fissures that would have allowed crud to get into the interior, which might contain anything.
Food-contact contamination in use
As far as wood becoming contaminated with bacteria specifically, the usual concern with food-related applications (and not actual dirt) this seems to be a non-issue in practice as long as basic hygiene practices are observed. The main thing is to physically clean residue1 from the surface by washing, the bacteria in the traces that remain (and there will be some) appear to be made inactive when the board/spoon/bowl dries out2 before it is used again.
Toxins/poisons on or in the wood before it was acquired
This is the major worry with found wood I feel. As far as I know there's no way to reliably identify this type contamination visually or with a simple test you can conduct at home.
Wood that may have been treated with preservative or that might have come into contact with dangerous chemicals in service should probably never be used for a project where it will come into direct contact with food, and even with a full coat of varnish or lacquer a cautious approach should be taken. It's usually impossible to know what a pallet might have come into contact with during its former life..... this is why some kitchen projects posted online that utilise pallet wood make me shudder when I see them!
Note: this is ignoring the risk to the woodworker themselves when processing the wood, which may be the greater risk. This is primarily from using power tools and when sanding.
1 The primary worry being meat juices. Especially, but not exclusively, from raw meats (includes all seafood). However it should be noted that soil residue from raw unwashed vegetables should be very scrupulously separated from food-preparation surfaces.
2 This is one of the arguments in favour of not finishing cutting boards, to retain the ability of the wood to dehydrate bacteria.