This verse (chaupai) is from the Balakanda chapter of Shri Ramcharitmanas.

सठ सुधरहिं सतसंगति पाई। पारस परस कुधात सुहाई॥ बिधि बस सुजन कुसंगत परहीं। फनि मनि सम निज गुन अनुसरहीं॥
This verse (chaupai) is also from the beginning of the Balakanda and occurs in the context of describing the importance of satsang (company of the virtuous).
Meaning : Even the wicked can improve through the company of the virtuous, just as iron becomes beautiful (turns into gold) upon touching the philosopher's stone. However, if by fate, a good person falls into bad company, they still follow their own virtues, like the gem on a serpent’s head. Just as the gem, despite being with the serpent, does not absorb its poison and continues to shine with its natural light, in the same way, a virtuous person, even in the company of the wicked, continues to spread light without being influenced by them.