Most bays are empty and easy. A few will have something running through them, and those few deserve your slowest, most careful work.
Gas appliance vents
If a metal vent from a furnace or water heater passes through or beside a bay, do not pack foam against it. Canadian instructions for one common double-wall gas vent call for a 25 mm (1 in.) minimum air space to combustibles and say to keep building insulation out of that space, in Selkirk's Type B vent installation instructions. Foam board and canned foam are both combustible, so they stay outside that gap. The exact clearance for your vent is printed on its label, and other vent types, including single-wall pipe and wood stove chimneys, need considerably more room.
The gap around a vent still leaks air, so it still needs closing. The right materials are a collar of sheet metal and a non-combustible sealant, and high-temperature silicones are made for flue pipes, as Natural Resources Canada's air sealing chapter advises. Plastic vent pipes from high-efficiency furnaces run much cooler, and their own installation manuals say what may touch them.
Canned foam has a temperature ceiling of its own. One widely sold product is labelled as combustible once cured, with a limit of 116°C, and its maker says it should not be used around heaters, furnaces or anywhere it may touch heat-conducting surfaces, according to the Great Stuff Pro product sheet.
Gas piping, wiring and exhaust hoods
Where a gas line passes through the rim, seal the small gap around the pipe and leave everything else alone. Do not bury shutoff valves, unions or flexible connectors in foam, and do not lean on or shift the pipe while you work. The federal advice here is to be careful around electrical wires and gas pipes and not to disturb connections.
Electrical cables can be foamed around where they pass through the wood. Junction boxes need to stay accessible, so cut the board around them and keep their covers clear. Dryer and bathroom fan hoods should be sealed around the outside of the duct, with the damper left free to swing.