य एवं सन्तमात्मानमात्मस्थं वेद पूरुष: । नाज्यते प्रकृतिस्थोऽपि तद्गुणै: स मयि स्थित: ॥ ८ ॥
ya evaṁ santam ātmānam ātma-sthaṁ veda pūruṣaḥ nājyate prakṛti-stho ’pi tad-guṇaiḥ sa mayi sthitaḥ
Though dwelling within material nature, one who thus knows the ātmā and the Paramātmā seated within is never touched by the guṇas, for he remains established in Me through loving bhakti-service.
When the Supreme Personality of Godhead appears in this material world, He is not affected by the modes of material nature. Similarly, those who are always connected with the Supreme Personality of Godhead, even though they be within the material body or the material world, are not affected by the material qualities. That is explained very nicely in Bhagavad-gītā (14.26) :
This verse says that one who realizes the Supersoul within is not tainted by material qualities, even while living in material nature, because he remains situated in the Lord.
In Canto 4, Chapter 20, Lord Vishnu instructs Prthu on spiritual realization and devotion, explaining how inner God-realization keeps a ruler and devotee free from contamination by the gunas.
Regularly cultivate awareness of the Lord in the heart through bhakti practices (hearing, chanting, prayer); this steadies one amid stress and temptation so actions are less driven by passion and ignorance.