Route permits
The rights for operators to fly scheduled services between two countries are negotiated as part of a Bilateral Air Services Agreement (BASA) between those two countries.
Each BASA specifies what "freedoms" or restrictions may apply to each party to the BASA to operate scheduled services. These can range from highly restrictive to highly unrestrictive (so-called "Open Skies" agreements). Some examples of restrictions include the number of frequencies, number of seats, maximum and minimum fares to be charged, type of aircraft to be used, which airports may be served, etc
Once an airline from a particular country decides that they want to serve a route to another country, they apply to their own Government (usually the Ministry of Transport or Ministry of Aviation) for "designation". This is basically a diplomatic note that the designating country sends the other country to specify that XYZ airline is permitted to exercise the rights negotiated under the relevant BASA. The ability to designate an airline is not always straightforward - many BASAs specify that a designated airline must pass a "substantial ownership and effective control" test to be accepted for designation. Lately, a more liberal "principal place of business" test has been adopted in some BASAs to recognise the multinational nature of airline groupings and globalisation of capital flows.
Once designation is accepted, the airline must obtain the relevant licenses and/or technical permits to operate scheduled services to the country in question. These can be very straightforward in most cases, but can also be extremely complex in others (such as the USA). These are intended in theory to ensure that the technical processes, training and other requirements to operate in a foreign country are aligned with the air safety and legal systems of that country. These permissions are usually issued in alignment with the IATA Summer and Winter scheduling seasons and need to be renewed accordingly.
After this is done, the airline needs to make commercial arrangements for their operations at the destination airports. In the case of Level 3 (Co-ordinated) and Level 2 (Facilitated) airports, this may include the requirement to obtain slots allowing take-off and landing at specific times. The allocation and management of slots themselves are subject to a whole host of regulations depending on the airport type and national regulations. Other arrangements include negotiation for landing and facility fees, ground handling agents, catering, cleaning, crew layover hotels, sales offices, etc.
When it comes down to the actual day of operation, the airline must file a flight plan that indicates the intended route to be flown. If this route takes them over a third country, they may be required to obtain permission in advance to fly over that country (these permissions may be required or waived as part of the BASA in place between those two countries). There may also be Advance Passenger Information (API) requirements for the destination country, or a country to be flown over. Depending on the cargo carried on board, there may also be compliance regulations for the destination and overflight countries.