As usual, you can just increase the effort one has to invest to steal from you. There is never 100% security. Your employees might copy and sell your code.
Nevertheless, there are multiple possibilities but they could be divided in legal, technical/physical, and strategic
Legal:
- Put a clear IPR and usage right statement in the contract
- Put the IPR statement in the code
- Request certifications
Technical / physical
- Provide object code instead of source code
- Provide interface descriptions instead of code
- Provide the office and / or development tools like restricted computers, e.g. no USB, no internet despite Stack Exchange :)
Strategic
- Implement a supplier development strategy
- Offer long term relationships to downgrade the quick-win "business case"