Hi there,
You are a quasi-employee of the hospital where your residency is located. You are considered in a educational program in that your actions are covered by the hospital (if you make a mistake you, the hospital and your attending can be sued) and your educational requirements are dictated by the specialty board of your specialty. Your work hours are dictated by the ACGME, the organization that approves your residency site.