Hello
I work somewhere that actually makes baked beans. The beans themselves are soaked in water for around 18 hours, before being drained and blanched in hot water. They are drained and then filled into the can. The sauce is prepared with salt (sodium) and sugar (and tomato puree, water, spices, starch etc) and is then filled into the can with the beans before seaming and heat processing.
The sodium is in the sauce but the beans contine to absorb liquid during the heat processing treatment and for a short period afterwards so some of the sauce is absorbed by the beans (including the sodium and sugar). The amount of salt and sugar in baked beans is actually quite low, and has been reduced further in the last few years, and baked beans are actually quite a healthy option as they are low in fat and sugar and a good source of fibre and protein. I could go on, but I'll resist the urge!
Hope that helps