I'm going on a one day hike, and I want to cook an egg whilst on it. I'd like to avoid carrying excess water, and the route goes past a couple of waterfalls and several streams, so there is no problem in acquiring extra water. However, I don't know whether there would be risks from bacteria in the water getting into the egg, meaning I would have to purify the water first.
First things first. You do not need to purify all water sources. Just because it is not out of a tap does not make it immediately dirty. Most fresh wilderness water (providing it isn't stagnant, etc.) is fine for drinking.
You should be familiar with the source of the water. Just because the river looks clean doesn't mean that an industrial unit isn't dumping into it upstream. I always check a river on a map before using it. Generally a mountain stream above human habitation will be fine.
Providing the water is fine for drinking there is no reason not to boil an egg in the same water, if anything it's going to be safer.
If the water is actually dirty (e.g. polluted, stagnant, in a built up area, etc.) Then no, don't boil your egg in it.
Most bacteria should be destroyed by the boiling, but things like heavy metals, etc. will survive boiling and this can either enter the egg (though the shell) or be passed onto the inner egg from the shell when you break it (cross contamination)
As someone with +10 years experience as a boyscout, i never had an incident or heard of an incident where cooking with wilderness water led to bacteria infections, sickness, etc.
You should take care not to use stagnant water (this was also mentioned in other answers) and I'd personally avoid very shallow streams, to avoid dirt and bacteria from the ground polluting the water.
If you want to be as safe as possible, make sure the water has been boiling for some time before putting the eggs in it.
On a sidenote:
Since it is supposed to be a one-day hike and you don't mention anything else, I assume that the trip will be somewhere near to you. If you are visiting a foreign country, I'd definitely make sure beforehand that the water sources there are safe to drink from (i. e. I probably wouldn't do this without proper water filtration in some African or South-American (or even European) countries).
Yes you can but the question you need to ask yourself is should you ? If the water is dirty it will contaminate the egg (some toxins are horribly bad for you)
Most fresh (flowing) spring water is VERY clean if above human habitation areas