The Magic Lamp is able to completely contain the Erazor Djinn and his powers within itself. When wielded, it gives the user full command over Erazor for the purpose of making him grant three wishes. If Erazor refuses, the lamp can shoot fireballs at Erazor which forces him to grant his master's wishes anyway. As implied by Shahra though, the lamp cannot be used by djinns.
Long ago, the Erazor Djinn was sealed inside the Magic Lamp as punishment for his crimes until he had granted the wishes of a thousand people. After serving his sentence, Erazor was free to continue his evil ways, though the Magic Lamp still held power over him. Under unknown circumstances, the lamp was crushed into a twisted orb and came into the possession of Shahra.
Sonic and the Secret Rings
When Sonic the Hedgehog found the Blue Ring, Shahra gave the Magic Lamp to Sonic, only telling him it would be their last resort for stopping Erazor. When Shahra was killed by Erazor, the Magic Lamp was restored as Sonic wished for Shahra to "go back to the way she was." After Sonic beat Erazor, he realized how the lamp worked and used it to make Erazor grant him three wishes: bring Shahra back to life, restore the world of the Arabian Nights and its storybook back to normal, and trap Erazor himself within the Magic Lamp until the end of time. After granting the final wish, Erazor was sucked into the Magic Lamp, sealing him within it once more. Sonic then threw the Magic Lamp into the lava pools in the Evil Foundry so no one could ever obtain it again.
Other game appearances
In Sonic Runners, the Magic Lamp appears as a Rare Fly Type buddy which increases the player's chances of getting a Gold Flicky by fifty percent.
During the "Desert Ruins" event, the Magic Lamps are one of the many treasures sought by treasure hunters. During one of their treasure hunts, Team Sonic acquire one from a sealed treasure chamber.