We were surrounded by mountains on all sides.
The village was surrounded by troops.
He was surrounded by fans.
The cake was surrounded with cherries.
He surrounded himself with yes-men.
The jacket was surrounded with a gold trim.
I don't know the answer, but my feeling is that it depends on whether 'what surrounds' is integral to 'what is surrounded'. That is, the cherries are part of the cake. They are integral to it. The yes-men are a necessary adjunct to 'his' self-important personality, and the gold trim forms part of the jacket........but.......
We happened to be surrounded by mountains at that point of our journey. The mountains add nothing to us and are not integral to us. The troops surrounding the village are presumably not there for the duration and will leave when their ominous duty is done. And the fans surrounding him will disperse as soon as he gets into his car and leaves.
'By' indicates a circle around what is surrounded. 'With' indicates that what surrounds forms part of the contour of what is surrounded.