If you pay somebody to write code for you, you can require them to agree that the code belongs to you as "work for hire". If they try to "steal it" you could sue them for copyright infringement and/or theft of trade secrets.
If you do not pay them, then you cannot enforce such a contract because there is no consideration. Even if they signed an agreement, a court will throw it out as an "unequal" contract. You can only demand something from someone when they are getting something concrete in return (called "consideration").
Speaking from experience, if I were you I would worry more about producing something, not trying to protect it. Most people spend way too much energy trying to "defend" their ideas which in most cases are worthless. I remember one guy who announced he was working on a brilliant software project so I asked "How is it going?" He says, "I haven't actually started it yet. I am still working on the disk copy protection scheme." Seriously, you are 17 and you are planning to sue somebody over code that does not even exist? Do you know how much it costs to sue somebody? It costs a $10,000 retainer just to walk into a lawyers office, forget about filing any papers.
Trust me, spend your time writing code, not worrying about people stealing it. Once you have made your first $100,000 and it is IN THE BANK, then maybe think about legal steps.