
662 F.3d 1114 (2011)
Alan STEIN, aka Allen Stein, Plaintiff-Appellant,
v.
Charles RYAN, Director of Arizona Department of Corrections; Maggie Urena, Arizona Time Computation Unit Supervisor; State of Arizona; Dora Schiro; Jane Doe Ryan; John Doe Schiro; John Doe Urena; John Does I-X; Jane Does I-X; XYZ Entities I-V, Defendants-Appellees.
No. 10-16527.
United States Court of Appeals, Ninth Circuit.
Argued and Submitted October 13, 2011.
Filed November 18, 2011.
*1116 Daniel Christopher Gregory, Esq., Gregory Law Firm, PC, Surprise, AZ; Thomas Norman O'Leary (argued), Phoenix, AZ, for the plaintiff-appellant.
Daniel Patrick Schaack, Esq., Assistant Attorney General, Arizona Attorney General's Office, Phoenix, AZ, for the defendants-appellees.
Before: J. CLIFFORD WALLACE and SIDNEY R. THOMAS, Circuit Judges, and LLOYD D. GEORGE, Senior District Judge.[*]

OPINION
WALLACE, Senior Circuit Judge:
Alan Stein appeals from the judgment of the district court dismissing his action against the State of Arizona and individual officials employed by the Arizona Department of Corrections (Department) for alleged negligence and alleged violations of his civil rights. The district court held that Stein failed to state a claim for which relief can be granted. We have jurisdiction to review the district court's judgment under 28 U.S.C. § 1291. We affirm.

I.
On August 1, 1997, Stein pleaded guilty in the Arizona Superior Court to a felony charge of attempted sexual contact with a minor. His offense occurred between October 15, 1995 and October 26, 1996. The judge suspended sentence, placed Stein on lifetime probation, and ordered that he spend one year in jail. Stein did not appeal his conviction or sentence.
On February 9, 2006, Stein appeared in Arizona Superior Court to respond to a charge that he had violated the terms of his probation. The court revoked Stein's probation and sentenced him to ten years in prison. Stein did not appeal his sentence. However, he later filed a petition for post-conviction relief.
*1117 On November 3, 2008, while Stein's petition for post-conviction relief was pending, the Arizona Supreme Court issued State v. Peek, holding that the statutes in effect between 1994 and 1997 authorized lifetime probation for certain completed offenses against children, but did not authorize lifetime probation for attempted child molestation. 219 Ariz. 182, 195 P.3d 641, 643 (2008). The parties agree that under Peek, the maximum probationary period authorized for Stein's 1997 conviction was five years. Thus, when Stein was sentenced in February 2006, he had already been on probation longer than authorized by statute. On February 23, 2009, the superior court vacated Stein's sentence, discharged him from probation, and ordered him released. In sum, Stein spent just over three years in prison pursuant to an erroneous sentence.
Stein filed a complaint in Arizona Superior Court requesting the State of Arizona and certain individuals employed by the Department to pay damages for the time he spent in prison pursuant to an illegal sentence. The defendants removed the action to the district court and moved to dismiss the case under Federal Rule of Civil Procedure 12(b)(6). Stein filed an amended complaint which prompted the defendants to again move for dismissal. The district court dismissed all of Stein's claims with prejudice. It also held that Stein had failed to state a claim of negligence against the State of Arizona because, while the Department had a duty to ensure that his prison sentence was calculated correctly, it had no duty to review the legality of his sentencing order. It held that Stein had not alleged facts to support a claim for infliction of emotional distress. With respect to Stein's claim against the individual defendants brought under 42 U.S.C. § 1983, the district court concluded that they were protected by qualified immunity. The district court also held in the alternative that Stein had failed to allege that they were liable based on their own actions.
Stein does not appeal from the dismissal of his claim for infliction of emotional distress. Rather, he argues that the district court erred in dismissing his claims for negligence and violation of his constitutional rights. We review the dismissal of Stein's claims de novo. Cousins v. Lockyer, 568 F.3d 1063, 1067 (9th Cir.2009).

II.
In order to recover on his state law negligence theory, Stein needed to prove four elements: "(1) a duty requiring the defendant to conform to a certain standard of care; (2) a breach by the defendant of that standard; (3) a causal connection between the defendant's conduct and the resulting injury; and (4) actual damages." Gipson v. Kasey, 214 Ariz. 141, 150 P.3d 228, 230 (2007). Stein's theory was that, upon receiving him into custody, the Department had a duty to identify the statute under which Stein had been sentenced and compare it to the sentencing order to ensure that his sentence was legal. Stein alleged that the Department failed to make this inquiry, causing him to spend three years in prison pursuant to an illegal sentence.
The district court rejected Stein's contention that the Department has a duty to review the legality of sentencing orders. Under Arizona law, the authority to control a sentence is distributed "so that the court, the department of corrections and the parole board each serves its purpose, and within its specified sphere of competence, individualizes the sentence." State v. Harris, 133 Ariz. 30, 648 P.2d 145, 146 (Ariz.Ct.App.1982). Courts impose the sentence, and the parole board or the Department (as the case may be) determine *1118 whether or not a prisoner is eligible for release. Id. While the Department must determine whether a prisoner is eligible for release pursuant to the terms of a sentencing order, that does not mean that it must review the legality of the prisoner's sentencing order. Just as a court has no authority to order the Department to release a prisoner prior to the expiration of the sentence, "but could only sentence him to a definite term of years in prison," id., the Department has no authority to refuse to enforce a sentence issued by a competent court. The review of sentencing orders is a judicial function, and the Arizona Constitution gives the authority to perform judicial functions exclusively to Arizona's judicial department. Ariz. Const. art. 3.
Stein's theory is that the Department had a duty to discover that the superior court imposed an illegal sentence and that the Department's failure caused him damage. We do not believe that the Arizona Supreme Court would hold that the Departmentan agency within Arizona's executive departmenthas the authority, much less the duty, to ensure that judicial orders comply with the law. The district court properly dismissed Stein's negligence claim.

III.
Stein also sought recovery under 42 U.S.C. § 1983 for alleged violations of his Eighth Amendment right to be free from cruel and unusual punishment and his Fourteenth Amendment right to due process. Stein's theory is that the defendants subjected him to cruel and unusual punishment and deprived him of liberty without due process by imprisoning him pursuant to an illegal sentencing order. According to Stein, if the defendants had properly calculated his sentence, they would have been obliged to release him immediately rather than hold him for three years.
Under certain circumstances, wrongful imprisonment may support a claim under 42 U.S.C. § 1983. An action under section 1983 has two essential elements: "(1) the defendants acted under color of law, and (2) their conduct deprived [the plaintiff] of a constitutional right." Haygood v. Younger, 769 F.2d 1350, 1354 (9th Cir.1985). Obviously, officers of a state's department of corrections who imprison a person in the state's prison do so under color of law. Such imprisonment violates the prisoner's rights under the Fourteenth Amendment if the prisoner does not first receive due process of law. Since imprisonment is punitive, officials who detain a person may violate that person's rights under the Eighth Amendment if they act with deliberate indifference to the prisoner's liberty interest. Id.
The district court held that the individual defendants were entitled to qualified immunity and, in the alternative, that Stein failed to state a claim because he did not allege any personal involvement by the individual defendants. Because we hold that the district court properly concluded that the defendants enjoy qualified immunity, we need not decide whether the claim was properly dismissed for failure to allege that the defendants were liable based on their own actions.
A public official is immune from an action under 42 U.S.C. § 1983 "[u]nless the plaintiff's allegations state a claim of violation of clearly established law." Mitchell v. Forsyth, 472 U.S. 511, 526, 105 S.Ct. 2806, 86 L.Ed.2d 411 (1985); see also Harlow v. Fitzgerald, 457 U.S. 800, 818, 102 S.Ct. 2727, 73 L.Ed.2d 396 (1982) (qualified immunity applies if official's conduct "does not violate clearly established statutory or constitutional rights of which a reasonable person would have known"). In order to determine whether the defendants *1119 are immune from an action, the court must answer two questions: (1) whether Stein alleged the violation of a constitutional right, and (2) whether that right was clearly established. Pearson v. Callahan, 555 U.S. 223, 232, 236, 129 S.Ct. 808, 172 L.Ed.2d 565 (2009) (leaving the courts to decide, in their sound discretion, which question to answer first). A right is "clearly established" if its contours are "sufficiently clear that a reasonable official would understand that what he is doing violates that right." Anderson v. Creighton, 483 U.S. 635, 640, 107 S.Ct. 3034, 97 L.Ed.2d 523 (1987). Also, the right must be defined "at the appropriate level of specificity." Cousins, 568 F.3d at 1070, quoting Wilson v. Layne, 526 U.S. 603, 615, 119 S.Ct. 1692, 143 L.Ed.2d 818 (1999).
Defining his claims at the appropriate level of specificity, Stein asserts a constitutional right not to be incarcerated pursuant to a sentencing order if that order is later determined to be invalid. It is undisputed that, in light of Peek, Stein's sentencing order was invalid. However, we hold that he did not have a constitutional right to be released prior to the time his sentence was vacated.
Stein did not allege a violation of his rights under the Fourteenth Amendment. The Constitution permits states to deprive a person of liberty as long as the person first receives due process. See Haygood, 769 F.2d at 1357 ("Process which precedes a loss of liberty obviously prevents a constitutional violation"). "The fundamental requirement of due process is the opportunity to be heard `at a meaningful time and in a meaningful manner.'" Mathews v. Eldridge, 424 U.S. 319, 333, 96 S.Ct. 893, 47 L.Ed.2d 18 (1976), quoting Armstrong v. Manzo, 380 U.S. 545, 552, 85 S.Ct. 1187, 14 L.Ed.2d 62 (1965).
Stein had an opportunity to be heard before he was convicted and placed on probation. He also could have appealed the order that erroneously set the term of his probation for the rest of his life. He had another opportunity to be heard before the court sentenced him to ten years imprisonment. He then could have appealed that order. He was afforded the opportunity to seek post-conviction relief and ultimately secured his release. Stein did not allege that he was ever denied an opportunity to be heard at a meaningful time and in a meaningful manner. Under Mathews, he received all the process that was due to him.
Stein argues, however, that the process he received was not enough. He contends that the defendantsmembers of the executive branchshould have reviewed his sentence sua sponte and concluded that his detention was illegal. Stein offers no authority requiring prison officials to review sentencing orders independently to make sure the court got it right. Prison officials may properly assume that they have the authority to execute the sentencing orders delivered to them by the court without fear of civil liability. Thus, Stein did not allege any violation by the defendants of his rights under the Fourteenth Amendment.
Stein's Eighth Amendment claim fares no better. His allegation that prison officials should have discovered that his sentence was illegal does not establish that they acted with deliberate indifference to his liberty interest. Prison officials have the duty to execute the sentencing orders delivered by the courts. They may have a duty to calculate accurately the prisoner's release date according to the terms of a sentencing order, but no reasonable prison official would understand that executing a court order without investigating its potential illegality would violate the prisoner's *1120 right to be free from cruel and unusual punishment.
The district court reasoned that "an official would not have known that a term of lifetime probation for the crime of attempted sexual assault with a minor was unlawful as there was no clearly established law so holding until Peek." Stein v. State of Arizona, No. CV 09-1505-PHX-MHM, 2010 WL 2541136, at *6 (D.Ariz. June 18, 2010). This reasoning does not mean that defendants may have violated Stein's rights by detaining him for the nearly four months between the time the Arizona Supreme Court issued Peek and the time Stein's sentence was vacated.
Peek made clear that Stein was entitled to have his sentence vacated as a matter of Arizona law. However, prison officials have a duty to enforce a sentencing order until the order is vacated or the prisoner otherwise becomes eligible for release. To say that defendants should have released Stein as soon as the Arizona Supreme Court decided Peek (or at any time prior to the court's order vacating sentence) would be to impose on them the judicial responsibility of reviewing the legality of a sentencing order. In other words, Peek may have given Stein the right to have his sentence vacated, but it was the vacatur of his sentence by the court hearing his case that gave him the right to be released. Even if Peek made it clear that Stein's sentence was erroneous, defendants did not violate his constitutional rights by holding him in prison while the sentencing order remained in force. Because Stein did not allege a violation of his Eighth or Fourteenth Amendment rights by defendants, they are immune from an action.

IV.
Stein failed to state a claim upon which relief can be granted. The district court, therefore, properly dismissed the action. The judgment of the district court is AFFIRMED.
NOTES
[*]  The Honorable Lloyd D. George, Senior District Judge for the U.S. District Court for Nevada, sitting by designation.
