I'm guessing it's from Asimov's Three Laws of Robotics.
Ed: according to Wikipedia I got it pretty close:
> First Law
> A robot may not injure a human being or, through inaction, allow a human being to come to harm.
> Second Law
> A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
> Third Law
> A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
https://en.m.wikipedia.org/wiki/Three_Laws_of_Robotics
Just remember, Asimov himself pointed out through his works that the three laws are not enough! :)