Pretty much any kind of poison you want. How the toxic octopus survives is really quite simple on any of the several avenues that you can take. Neurotoxin, haemotoxin, cytotoxin, targets an organ, etc, really, the choice is yours. It depends largely upon the action of the poison.
Immunity boils down to:
- the cellular or molecular structure of the thing to be or not be poisoned,
- the metabolism of the thing to be or not be poisoned,
- and the structure of the poison.
Examples of immunity or lack thereof:
- Chocolate is poisonous to dogs.
- Aspirin is poisonous to cats.
- Birds can't taste capsaicin (in hot chillis).
- Fleat treatments don't kill pets if applied properly.
- Stomach acid (normally) doesn't cause damage to the animal containing that stomach
In the first two cases the animals lack enzymes to break down one or more chemicals which then travel to and damage organs (largely the kidneys). In large doses humans will suffer damage too but in typical doses our bodies can metabolise the chemicals before this happens. In the third, there is no cell in a bird that the capsaicin can bind to, but in humans we can easily and painfully sense it in our mouths, noses, eyes and anuses. The fourth is similar, mammal nerve cells aren't the right shape to be as badly affected as insects. The last is due to a protective stucture, notably a neutralizing mucus.
Neurotoxins produced by animals are proteins, since animals are good at producing proteins, though plants and bacteria produce them too and there are nerve poisons that aren't proteins. Typically they act by binding to nerve cells.
Nerve cells in one type of animal are often different to those in another type of animal. Cobra venom can't poison cobras because on a molecular scale cobra nerve cells are simply the wrong shape to be poisoned. The cobra nerve cell receptor is the same shape as in mammals but nearby the cobra has some other atoms that the big venom molecule can't fit past. Animal flea treatments are neurotoxins but insect nerve cells are different to mammal nerve cells. Your dog isn't killed by having flea poison dropped onto the back of his neck because he, like you, is much less sensitive to the poison than are insects but if he got all that in his mouth it would be dangerous.
Poison dart frogs eat, what is to us and most of their predators, deadly poisons. But their nerve cells are simply not the right structure to be affected and the frogs accumulate this poison to deter predation.
Similarly, many herbicides have no notable effect on animals but others do, like, Agent Orange. The cell structure of animals and plants are different.
If you wanted, the toxic agent could result from a breakdown of one chemical into others. Chemical A isn't poisonous to octopus but in humans it breaks down over time into chemicals B and C, one of which is toxic. Just throw on a cyanide group (they're common) that is released when it's metabolised.
Haemotoxins work by an enzyme (often several) attacking proteins, proteins being a huge part of the human body (and all animals). Snakes, such as most vipers, produce haemotoxins that lead to loss of blood clotting, destruction of tissue around the wound (necrosis), a lot of pain, dissolution of internal organs. These venoms need to enter the bloodstream or otherwise make it into the internal organs. Skin, hair and nails simply aren't affected, or are affected only slowly, even through they are made of proteins. When a snake eats another snake, any poison organ is eaten intact and any haemotoxin is destroyed during digestion.
To avoid these effects the toxic creature would have to produce a neutralizing agent (and some snakes have been observed to produce antivenom), isolate it (with resistant cells), or simply not contain a protein that could be affected by the enzymes (the enzyme can't attack that shape of protein). For example, the enzymes in snake venom that destroy tissue protein are also proteins, but the enzymes are shaped to attack other proteins, not themselves.
Chemotherapy is tailored so that the toxins used preferentially kill cancerous cells (well, it preferentially targets dividing cells, healthy or cancerous, but it relies on cancerous cells doing that more often).