Depends on the story, and IIRC it has shifted with time. But yeah, the general trope is they are stuck in a small vessel, and they offer/are extorted into one or more wishes to free them. Why they are stuck ranges from evil sorcerer trying to enslave them to noble hero stopping their rampage.
I like the idea that genies aren’t obligated to serve you and if your wish is bullshit, they just kill you.
Supposedly they are malevolent spirits that sometimes may grant wishes as a reward, not by some compulsion.
Depends on the story, and IIRC it has shifted with time. But yeah, the general trope is they are stuck in a small vessel, and they offer/are extorted into one or more wishes to free them. Why they are stuck ranges from evil sorcerer trying to enslave them to noble hero stopping their rampage.