I'd put the foil towards the sun to reflect the energy rather than absorb it.
You would think so, but this is actually exactly the wrong advice.
If you leave a mirror or shiny piece of metal out in the sun, you will notice that it gets quite hot. With enough sun, it will get too hot to hold. A white piece of plastic however will hardly get warm at all. So what's the reason behind this? Reflecting the heat is only part of the issue, and in this case, is not all that important.
What is important is emissivity. In the case of the foil vs foam surface, the foil has a low emissivity, and the foam has high emissivity.
Emissivity is a measure of how much heat a material radiates as it gets hot. In the case of the foil, the answer is not that much. So while that hypothetical mirror above may reflect 97% of the heat that is radiated onto it, that small 3% proportion of absorbed heat is largely not re-radiated back out until the surface gets quite hot. In the case of the white plastic, maybe only 90% of the heat radiated onto it is reflected, but that 10% that is absorbed is also easily re-radiated back out.
By placing the foil on the INSIDE, even when the foam gets hot, very little infrared energy will be radiated back inside the house. That's what the foil surface is there to help with.