Sheffield Crown Court was told how on August 15 last year, Charlene Thompson visited her then partner Jonathan McGregor at HMP Marshgate in Doncaster.
Prosecuting, Stephanie Hollis, described how at the end of the visit the couple hugged goodbye, and a prison guard watched as McGregor reached inside the waistband of Thompson's clothing, pulled out a small package and put it in his pocket.
She said: "He was searched and he threw a package on the floor."
Inside the package prison officers found a quantity of cocaine with an estimated prison value of around £200.
They also found nine tablets of Buprenorphine, which is a Class C drug, and a synthetic cannabis powder (which was not illegal at that time) concealed within the package
Thompson, aged 30, who had been in a relationship with McGregor for around seven months at the time of the incident, was arrested the following day and was subsequently charged with two counts of taking a controlled drug into prison.
McGregor was on remand at the time of the offence, and has since been sentenced to 24 years in prison for one count of attempted robbery, one count of using a fire arm with intent and one count of grievous bodily harm with intent.
An additional 28 days was added on to McGregor's sentence for attempting to smuggle the drugs into prison.
The court was told that Thompson, of Sheffield, had been given the package by a third party and had been coerced into taking it into prison for him, and since admitting to the offences at an earlier hearing she has been the victim of what is believed to have been a targeted burglary and assault.
She has since moved home as a result.
In mitigation, Judge Michael Slater was told that Thompson, a single mum of two girls, had suffered domestic abuse at the hands of both McGregor and her former partner.
He sentenced her to two years in prison, suspended for two years and ordered her to complete a 20-day rehabilitation activity requirement.
"You were with Jonathan McGregor for seven months, and during that time, it seems to me, you became aware of a different side to him to what you had previously expected," said Judge Slater.
He added: "Through a third party you were asked to take drugs to him in prison.
"Such an offence usually means a term of immediate custody because of the serious nature of taking drugs into prison when the value is greatly inflated and used to build a network.
"My judgement is that the sentence can, and will, be suspended. I have regard to the fact you suffered such appalling abuse in a previous relationship, before McGregor, you had to go into a women's refuge.
"It seems to me that it would be inhumane to send you to prison."