The first thing is that you have to go through immigration and customs. However, not all countries and airlines require you to do so. To some, a visa may be necessary to enter the nation you are currently in. Leaving the airport during a layover without a visa is a violation of airport policy.