There's an ongoing tension in Christian theology over the extent to which the Holy Spirit is operative in the world. For example, Justin Martyr argued that since the Greek philosophers had found truth, they must have been indwelt by the Truth.
Calvin too comments on this:
The swift and versatile movements of the soul in glancing from heaven to earth, connecting the future with the past, retaining the remembrance of former years, nay, forming creations of its own—its skill, moreover, in making astonishing discoveries, and inventing so many wonderful arts, are sure indications of the agency of God in man.
Institutes of the Christian Religion, 1.5.5
The question is how this can be squared with the clear fact from Scripture that the Holy Spirit only indwells those who trust in Christ.
For those who are led by the Spirit of God are the children of God. The Spirit you received does not make you slaves, so that you live in fear again; rather, the Spirit you received brought about your adoption to sonship.
Romans 8:14-15, TNIV
So what are we to make of the way that non-Christians often do things that lead to truth and goodness and so on? And it's important to recognise that they do - all too often, Christians tend to forget that. The stereotype I guess is that conservative evangelicals forget that non-Christians do good stuff at all, charismatics see it as the work of the Spirit and get on board with it and liberals go one step further and conclude that those people are ok without knowing Jesus.
I was pondering this tension a few weeks ago, and I came to the conclusion that it makes most sense if the work of the Spirit among those who aren't Christians is primarily to maintain what is left of the image of God in them. We were created good, and though our rebellion against God affected every part of us so that nothing we do is ever wholly perfect, it didn't affect every part of us totally - it is rare that anything anyone does is ever wholly evil either. When non-Christians do what is right, it is reflecting a bit of the glory of the God who originally made them and continues to sustain them.
I think that by identifying the work of the Spirit in the non-Christian world primarily with maintaining the remnant of the image of God in people, we get rid of what is otherwise a difficult tension.