The cleric spell Sanctuary lasts long enough for a cleric to enter the pit, pick up the treasure and exit the pit.