IANAL of course but it's probably not illegal, as in, you're not going to find yourself in a cop car or a courtroom for selling candy out of your backpack.
It's probably against the rules of your school, as in, the administrators can probably find a rule you're breaking and shut you down if they want to. A reasonable administration would just ask you to stop, but since when are school administrators known for being reasonable? The most likely consequence is getting your stash confiscated and a detention. There's probably an outside chance of a suspension if the administrator is particularly draconian or has some grudge against you.
Whether that would be a problem is between you and your parents. A suspension is not going to send you down the road of delinquency and destroy your future, but if it would disrupt your family harmony, maybe you clear your plan with the admins first.