This is probably very basic for some of you, but I'm new to this, so....
We read in Phillippians 2:12
"Wherefore, my beloved, as ye have always obeyed, not as in my presence only, but now much more in my absence, work out your own salvation with fear and trembling."
How can we do that if we cannot earn our way to Heaven?
This isn't meaning to 'do works of your own power and will which will earn you salvation' but as others have commented, this is meaning 'that which works in you works to your own salvation'; the idea that you acknowledge God to 'work' these things out through you, to your own salvation, even in troubling times, do not resist what God is accomplishing through and for you, but allow it to be worked out through you.
This is the mind of Christ of which the apostle speaks. Jesus was not afraid of His enemies because He knew that God was behind them all (even if they didn't know it) and was working through them and through Christ for the purpose of the glorification of His Son. Many times people won't comprehend that what are perceived as 'bad things' are in fact, very good things in the end of it.
So, Peter tried to stop the guards from taking Jesus to the cross, and what did Jesus do? He told Peter to put his sword away. Not to fight, because these things are all the will of God in our lives. We never need resist those things that happen to us, as we should know that even the bad things are the will of God in our lives. Forgive me to speak a little long here, but at Mark 8:31-33 we see Jesus speaking of His death and Peter stands in opposition to this, not understanding that this is the will of God (Peter is not understanding that the bad things, are good things which 'work out' our spirit to the glory of God, and our own salvation) and Jesus calls Peter 'Satan' in this instance. Because Peter has become an adversary to the will of God, and wants to stop it from happening.
Now, here are some passages I will keep to a minimum, but will more fully convey this idea:
Romans 5:3 Now you see why we glory in tribulation? Because tribulation works patience, and we want patience. So we willingly endure tribulations when they come, knowing they are sent of God for our own good, in the 'working out' of our salvation, or, as a means of transformation, bringing us closer and closer to the image of the son.
2 Corinthians 7:10 Now we see again this 'sorrow' which works out repentance. So we understand that the purpose behind sorrow is a good purpose, in that God is sending these trials and tribulations upon those He loves in order to bring them out of darkness and increasing in light the more and more to the fulness.
1 Thessalonians 2:13 We see here that it is indeed the very Word of God that is working in us, to guide us and push us along this working out of the salvation for the goal of gloification.
James 1:3 Again we see that trial works out patience; 'bad things' work out 'good things'; no pain, no gain, we might say.
Colossians 1:29 Now we see that our labor itself is according to the working of God in us, and that not of ourselves.
Galatians 5:6 You see it is faith itself which itself is the working of love; that is, the love of God toward us.
Now here are a few verses from the cited letter:
Philippians 1:28-30 Now we see the apostle telling us, not to be terrified of our adversaries. Most men are afraid of adversity because they don't understand the purpose of adversity. But what did Jesus say to Pilate? He said: John 19:11 You see, Pilate mistakenly thought these things were under his power, and will, and control- but they were not. None of these things could be done unless God allowed them to be done, and if God allows it to be done, then it is for the working out of good in us. Thus, never be afraid of anything at all, because nothing can do any hurt to us unless God has sanctioned this; and if God has sanctioned it, then do not resist it, nor run or fight; but submit yourself to the will of God, even to the point of the cross. And glory follows, in that of, the resurrection.
Philippians 2:5 You see, let this mind be in you, this mind of Christ which gladly endures all that God sets before Him; who did not call down legions of angels to resist the will of God, be He Himself humbled Himself to suffering according to the will of God, and the salvation of the world: Philippians 2:8
Philippians 2:12-13 Now we come to the cited verse, yet be sure to note the verse following, and understand that it is the work of God which works in you, working out your own salvation.
Philippians 2:15 You see, that we may be blameless and harmless; unlike many others who said 'I am the Christ' and lead many to resist the Romans to their death; yet Christ did not revile, nor fight back, but 'worked out' His own salvation through the workings of God in Him, as should we, and to be called, holy and blameless in the sight of God.
1 Peter 2:23