Based on what I've seen, anyone can write code, just as anyone can learn math or write a story. Further, anyone who devotes time and effort to writing code (or doing math or writing a story), who immerses themselves in it, who learns and practices, can write code well. Thing is, most people aren't motivated to do everything well. People find enjoyment in different ways; some through working with their hands, some through solving puzzles, some through talking to people. I wouldn't say this is purely natural (I didn't discover programming until later in life thus I'm nowhere near how skilled I'd be if I started at 10, although once I knew what it was I knew I would enjoy it), but I wouldn't say it's purely up to environment either. Anecdote: I introduced a friend of mine to programming recently. He can do it, and he's not bad at all, but he'd much rather be face-to-face with someone than staring at a screen for hours.
So, anyone can become a good programmer, but most won't want to be.