See also the indwelling of the Spirit in Hermas and in the apocryphal scripture quoted in James 4:5:
James 4:5: "He yearns jealously after the spirit (to pneuma) which he has caused to dwell (ho katókisen) within us (en hémin)". Hermas, Mand. 3.1: "Love truth, and allow only truth to come from your mouth, so that the spirit (to pneuma), which God caused to dwell (ho ho theos katókisen) in this flesh (en té sarki tauté), may prove to be true in the sight of all men".
Hermas, Mand. 10.2.4-5: "Both are a cause for grief for the Holy Spirit, double-mindedness (dipsukhia) and an angry temper. Rid yourself, therefore, of grief and do not oppress the Holy Spirit (to pneuma to hagion) that dwells in you (en soi katoikoun)".
In Hermas, each negative emotion is a separate "spirit" that takes up residence in a person, crowding out the Holy Spirit: "An angry temper is first of all foolish, fickle, and senseless. Then from foolishness comes bitterness, and from bitterness wrath, and from wrath anger, and from anger vengefulness; then vengefulness, being composed of all these evil elements, becomes a great and incurable sin. For when all these spirits dwell in one vessel, where the Holy Spirit also dwells, the vessel cannot contain them, but overflows. So the sensitive Spirit, which is not used to living with an evil spirit nor with harshness, departs from a person with the evil spirits" (Mandate 5.4-6). This concept may depend on such texts as Numbers 5:12-14, 29-30 (LXX) which refers to a "spirit of jealousy" (pneuma zélóseós), and similar ideas are found in the Testaments of the Twelve Patriarchs:
"You do these as well, my children, and every spirit of Beliar will flee from you ... so long as you have the God of heaven with you and walk with all mankind in purity of heart" (Testament of Issachar 7:7).
"The spirit of jealousy and pretentiousness kept saying to me, 'You too are his son.' And one of the spirits of Beliar was at work within me....Anger is evil, my children, for it becomes the motivating force of the soul itself....When the soul is continually preturbed, the Lord withdraws from it and Beliar rules it. Observe the Lord's commandments, then, my children, and keep his Law. Avoid wrath, and hate lying, in order that the Lord may dwell with you, and Beliar may flee from you...Throughout all your life love the Lord, and one another with a true heart...Draw near to God and to the angel who intercedes for you" (Testament of Dan 1:6-7, 3:1, 4:7-5:1, 3, 6:2).
"Even if the spirits of Beliar seek to derange you with all sorts of wicked oppresion, they will not dominate you....The deliberations of the good man are not in the control of the deceitful spirit, Beliar, for the angel of peace guides his life. For he does not look with passionate longing at corruptible things, nor does he accumulate weath out of love of pleasure. The good set of mind does not receive glory or dishonor from men, nor does it know deceit, or lying, or conflict, or abuse. For the Lord dwells in him, illuminates his life, and he rejoices in everythng at every appropriate time. The good set of mind does not talk from both sides of his mouth ... there is no duplicity in its perception or its hearing. (i.e. not double-minded)" (Testament of Benjamin 6:1-6).
"Beware of the spirit of deceit and envy. For envy dominates the whole of man's mind and does not permit him to eat or drink or to do anything good. Rather it keeps prodding him to destroy the one whom he envies. Whenever the one who is envied flourishes, the envious one languishes....If anyone flees to the Lord for refuge, the evil spirit will quickly depart from him, and his mind will be eased. From then on he has compassion on the one whom he envied and has sympathetic feelings with those who love him; thus his envy ceases" (Testament of Simeon 3:1-6).
Such concepts thus were devised to posit a spiritual source for bad feelings and vices. In ancient Judaism and Christianity, these concepts were mythologized further....particularly in the Enochic corpus. In the Pseudo-Clementine Homilies, the demons are identified as the "souls of the deceased giants" (8.18-19), whereas their angelic parents were seized and imprisoned for eternal punishment. These wandering demons, having lost their original Nephilim bodies, continually seek new bodies to find refuge. These "possessions" give rise to sin and vice: "Wherefore you are polluted in body and soul, and in the present life you are tyrannized over by sufferings and demons, but in that which is to come you shall have your souls punished" (8.22).
More on James, Hermas, and other sources cited here:
http://www.jehovahs-witness.com/10/80498/1.ashx