When Kingpin took over the Hell's Kitchen School for Troubled Youth, he imprisoned the students who didn't agree with his methods, Elektra was one of those students.
Elektra eventually freed herself, and came to the Avengers Academy looking for her former boyfriend Matt Murdock who had joined the Academy, after arriving there she also joined the Academy.
Elektra created Code Red with the intent of defeating the demon that powered the Hand ninjas, and with that, help the Avengers Academy students defeat them.
In reality Elektra was doing this for selfish reasons, since she wanted something the demon had. After failing their mission, and the team being dismantled, questioned by Daredevil as to why she put him, and the other members in danger, she told him why she did what she did, and also that if she actually wanted to defeat the Hand she would just infiltrate the organization, and become their leader.