Your code simulates attraction TO a sphere not INSIDE a sphere.

As per an earier post, gravity inside a hollow sphere is zero and gravity inside a non-hollow sphere is dependent on how much mass is the sphere "beneath" you so to speak.

If you just want gravitational attraction between bodies, then freakys code is right on. If you truly want gravity INSIDE a sphere, you'll have to follow what I said above and use some other scheme.