The short answer is yes, you can use spray foam to seal around the perimeter of the box, but there may be a bigger issue involved. All recessed light fixtures can be divided into two categories:
- those designed for contact with the insulation in the surrounding ceiling structure carry an “IC” rating
- those that cannot safely have insulation touching them are non-IC fixtures
IC recessed fixtures are made so that there are no holes or joints in the fixture body that allows indoor air to escape into cold attic spaces above. As long as the drafts you feel are coming only from around the edges of the fixture, then sealing will solve the problem. If, however, you feel drafts also coming from holes inside the metal light fixture body that surrounds the bulb, you’ve probably had non-IC fixtures inadvertently installed where IC fixtures were required. I hope that’s not the case. Ask your electrician about this, but also investigate the fixtures themselves. True IC lights have completely sealed bodies, while non-IC fixtures have visible holes in and around the body.