In the original film, the cave is visited at the very beginning by Jafar, Iago and a thief named Gazeem. The location of the cave was revealed using a mystical golden Scarab Beetle, which also helped form the cave. Jafar orders Gazeem to go inside the Cave to retrieve the magical lamp. The Cave's tiger head warns the visitors that only one may enter, referred to as the Diamond in the Rough. Jafar not understanding what he means decides to order Gazeem to go in again. Gazeem makes one step inside. When everything seems to be fine the Cave roars and shuts it's mouth killing Gazeem. Jafar then realizes he must find the Diamond in the Rough.
Back at the palace Jafar takes the Sultan's mystic blue diamond ring in order to power his device. The device shows just who the Diamond in the Rough is. It is revealed to be the cunning street rat, Aladdin. Jafar orders the guards to capture Aladdin and take him to the Palace's prison. There Jafar, disguised as a begger takes Aladdin and Abu to the Cave.
Aladdin and Abu successfully enters the cave, but while in there Abu touches the forbidden treasure. The cave starts to fill itself with lava and Aladdin and Abu nearly escapes with the help of Magic Carpet but is thrown down as Jafar who thought he had stolen the lamp. The cave then dissolves with Aladdin, Abu and Carpet still inside.
Inside the cave it is revealed that Abu stolen the lamp back from Jafar. Genie is released and Genie frees them. At the very end of the film after the big battle Jafar and Iago are trapped in there own lamp and imprisoned in the Cave of Wonders.
role in the series
in the agrabah campaign, the cave reprises it's role from above, but it also now has an eel servant who attacks spongebob and mr. krabs once the alarm is set off by abu.