Of course going hundreds or even thousands of feet into a pitch black, silty underwater cave with the only reliable air source those thousands of feet away has inherent dangers. Fortunately those dangers are well known and can be mitigated. There are 5 golden rules to cave diving (in decreasing order of the number of deaths caused by breaking them):
Training: don't ever do a dive for which you don't have the training or experience - this has been the number one cause of deaths in underwater caves
Guideline: always have a continuous guideline to the surface so you can safely exit in blackness or in zero visibility (silt)
Air: always reserve 2/3rds of your gas for your exit
Depth: nitrogen narcosis will hamper your abilities and affect your judgment.
Lights: Always have at least three lights, one primary and two backups.
To mitigate the risks of gear failure, redundancy is key. At the full cave level, double tanks are always used. Each tank has its own valve to which a regulator is attached and the tanks are connected via a manifold that can be closed to isolate them. Should a connection between a tank and a regulator fail, that valve can be shut down and all of that tank's gas can be accessed by the other regulator via the manifold. Should the tank's valve fail (e.g. a burst disk or the tank neck o-ring failing), that tank can be isolated by closing the manifold so that air from the other tank isn't lost. Since 2/3rds of your air is reserved for the exit, losing half of your air at any point in the dive, you would still have enough air to make the exit.
Should a catastrophic failure occur (loss of air in both tanks - an extremely rare condition), air can be shared from other members of your team. To make this possible, cave divers always use a 7' long hose. This is required since many areas of a cave may only allow one diver through at a time and only a hose long enough to go the length of the diver would permit this.
Other equipment that is used includes safety reels or spools. These are used should a diver become lost off the line or someone in his team become lost. If I were to find myself lost off the line, I would deploy my reel and tie it onto a nearby rock in the cave and start searching for the line. This is done so I don't become even more lost and loose my reference to my starting point. Should someone in my team become lost, I would tie my reel into the line and begin searching for him.
Markers called line arrows and cookies are used to indicate the direction out or mark a location within the cave. These are small pieces of plastic with slots on them that can be placed on the line. Line arrows are exactly that, arrows. Cookies are discs that don't indicate a direction to others in the cave (but may be used to indicate a direction for you - e.g. by placing them on the exit side of a junction on two lines).
Other equipment is also used for cave diving. Cave divers use two dive computers, two masks, two knives, etc. The only things we don't carry two or three of are dry suits and sets of fins.
By using redundant equipment and adhering to the five rules of cave diving, the risks can be reduced to the point where people have made thousands of safe cave dives and I can only think of two examples of someone dying without breaking the five rules (one was a heart attack, the other was a cave-in).