There's quite some more to say about Interlining and Codesharing.
# Interlining
Interlining is the ability to sell tickets on flights from another carrier.
This can be done for pure operational reasons (e.g. DL and AA during irrops: DL can book people on AA flights, but doesn't offer this on their website).
It can also be done for commercial reasons: e.g. DL and Airlink (South Africa), for connections through JNB which can be booked on DL's website. Here, often commercial agreements are in place so the airlines together offer attractive deals.
Sometimes it is legally imposed for anti-trust reasons. Example: DE has access to LH feeder flights to FRA at attractive fares, imposed by the German government. A similar agreement exists between VS and BA at LHR.
# Code sharing
For code sharing, many more rules apply from a government point of view.
1. The carrier adding the code, must have bilateral traffic rights to the destination.
2. The carrier operating the flight, must adhere to all rules imposed by the governing agency of all carriers adding their codes.
From a passenger PoV, it is a certain safeguard for safety.
E.g.: airBaltic obtained FAA Cat 1 approval in 2023. Delta and BT only then upgraded their existing interline agreement to a codeshare agreement: https://onemileatatime.com/news/delta-airbaltic-partnership/
Other example: LH, LX, AC and ET received fines in 2024 from the FAA, as their flights crossed airspace that was prohibited by the FAA, while carried UA codeshare flight numbers.