Wrapping food in foil will keep the food warm for a short time since the heat from the food will be somewhat trapped inside the foil.
However the foil won't keep the food warm for longer than an hour or so so it's best to put the food in an insulated lunch bag if you need to keep it warm especially while traveling.
Placing the food wrapped in foil inside a plastic bag can help to retain the heat a bit longer than just the foil though.