A Styrofoam cooler does a good job of keeping things cold because the material is a poor conductor of heat. A closed container of Styrofoam creates a “cold zone” into which heat from the outside enters at a very slow rate. Styrofoam has good insulating properties because it has millions of tiny air bubbles that slow the progress of heat through the material.
TL;DR (Too Long; Didn't Read)
Styrofoam is an insulator, which means it'll help keep the heat from the environment out of your cooler. However, you'll still need cooling agents (like ice packs) to make the cooler cold in the first place.
All materials have a property scientists and engineers call thermal conductivity -- the ability to conduct heat. Some substances conduct heat very well, while others conduct heat poorly; both types of materials are useful in the right circumstances. For example, a frying pan should conduct heat efficiently, heating up quickly and keeping the same temperature across its surface for even cooking. An oven mitt, however, should conduct heat poorly to protect your hands from hot cookware.
Conductors and Insulators
Metals are good conductors of heat because metal atoms share their outer electrons readily; this allows metal objects to transfer heat energy rapidly. Copper is one of the best heat conductors with a thermal conductivity of about 20,000 times greater than air. A few nonmetals also make good conductors of heat; diamond for example, has over twice the thermal conductivity of copper. Generally, however, most nonmetallic materials such as helium and sand are poor conductors of heat. Styrofoam is made of the plastic polystyrene, a nonmetallic solid with low thermal conductivity.
Solids and Air Bubbles
In general, solids make better heat conductors than liquids or gases, and gases are the poorest of the three states of matter. Styrofoam is structured as microscopic air bubbles contained by relatively stiff walls. In addition to making the substance lighter, the bubbles reduce the material’s thermal conductivity to a value only slightly higher than that of air.
Ice and Cold Packs
Although a simple Styrofoam container keeps things cold for long periods, it doesn’t make them cold if they’re already warm. And even though the material is a good thermal insulator, some heat does pass through it, albeit slowly. To counteract the heat that enters the cooler, and to chill items that might have been at room temperature, ice and cold packs reduce the cooler’s interior temperature.