What is meant by "possessed by spirits" in Buddhism? In this answer there is a quote from The Buddhist Monastic Code 1 - The Patimokkha Rules Translated and Explained by Thanissaro Bhikkhu, which reads in part 


  only when one is possessed by non-human beings


In that book there are several references to being possessed by spirits or non-human beings, such as this from page 44.


  State of mind. The bhikkhu must be in his right mind. Any statement he
  makes while insane, delirious with pain, or possessed by spirits does not count.


My question is, who or what is doing the possessing? Is there a belief in Buddhism that some being (a hungry ghost or something else?) would actually take over the mind of a human? Is that type of cross realm interaction possible? 

How literally is possession by spirits to be understood? Thank you.
In my tradition, the Shambhala line of teachings by Chogyam Trungpa Rinpoche, ascending to Jamgon Kongtrul and ultimately Milarepa, the "spiritual" and the "material" phenomena are understood to be two narrative explanations of the same underlying reality. So when we talk about supernatural stuff like spirits etc. we always refer to phenomena that actually happen in everyday life but lack adequate representation in the mainstream narrative.

In modern language, spirits are semi-stable configurations of information-causation that inhabit the noosphere and sustain themselves through behavioral patterns mediated by sentient beings.

To give an example you can relate to, you send your child to a summer camp and they come back intoxicated by the camp spirit. They act funny, and when you point it out, they say we don't get it and insist their gestures and attitude are their own, while you clearly see they've picked it up. After several days home the camp spirit rubs off. 

...In the adult world there may be a spirit of organization that influences all employees in certain ways etc...

Another example is campaign spirit - your teen daughter goes to a Greenpeace lecture and comes back possessed by the Greenpeace spirit. She donates her money to the ecological causes, spends her summer washing the birds caught in the oil spill etc.

If you look at it this way, you will see the world full of spirits, large and small. Your husband purchases a new camera, and feels obliged to spend his weekend taking pictures - he is possessed by the camera spirit.

These all seem harmless, until you remember all harm and violence incurred by religious and political fanatics - possessed by their respective spirits.

I don't know why late Theravada's Pratimoksha discounts misdeeds done while possessed by the spirits. From my perspective, guarding the doors of the senses is responsibility of the practitioner, and it is due to incorrectly applied attention that possession by spirit occurs. In the highly competitive world, where we are constantly bombarded by ads, campaigns and other forms of spirits, we must be very selective when it comes to which ones we give our attention to. As said in that Native American folktale, whichever wolf we feed is getting stronger. So is with spirits.

We can let ourselves be driven by spirits that correlate with greed, hatred, and confused values -- or we can feed useful spirits, conducive to health, peace, harmony, and informed, educated, strategic attitudes.

Buddhism itself can be seen as a spirit, and as any spirit can only take us this far until we become its pawns. So in the advanced stages of Vajrayana practice, our game becomes to liberate ourselves from the spirit of Buddhism, just like we've worked to come out of influence of worldly spirits. Once we are past that phase, having awakened (bodhi) from the spirit dream, we can use spirits as tools to pay our student dues forward and save the rest of sentient beings from the matrix into the real world.