The "particle in a box" model describes a particle which is bound to move inside a defined region of space and can't get out. In one dimension this means we are forcing the particle to move inside a segment $[0, L]$ but besides this, we are not imposing any potential on the particle, so inside this box there is no potential term (we can set any constant potential to zero without loss of generality).
Now we know that the stationary solutions to this problem have to satisfly the time independent Schrödinger equation (TISE) which is
$$
-\frac{\hbar^2}{2m}\partial_{xx}\psi(x)+V(x)\psi(x) = E\psi(x)
$$
so how do we choose our $V(x)$ to reproduce this problem? Simple, we define it as
$$
V(x) = \begin{cases}
0 \;\;\;\;\;\, x\in[0, L]\\
+\infty \;\; x\notin [0, L]
\end{cases}
$$
The way to solve the TISE now, is to divide our domain in three pieces $x\leq 0, 0<x<L$ and $x\geq L$ and solve the equation in each of these pieces. Then we need to make sure to glue together all the pieces of our solution because the TISE only admits continuous solutions (or taking the derivative we would get an infinite value).
Now, in the region where the potential is infinite the term $V(x)\psi(x)$ can be finite only if $\psi(x) = 0$ and this is the only case in which the TISE can be satisfied in this region, so we found that outside of the box the wave function vanishes. This is completely fine, because we set the infinite barrier exactly to reach this goal. Let's now look inside the box, here the potential is set to zero, so the equation to solve is
$$
-\frac{\hbar^2}{2m}\partial_{xx}\psi(x) = E\psi(x)
$$
which we can rewrite as $\psi_{xx}(x)+\Big(\frac{2mE}{\hbar^2}\Big)\psi(x) = 0$ and by defining $k \equiv \sqrt{\frac{2mE}{\hbar^2}}$ we can write this as
$$
\psi_{xx}(x)+k^2\psi(x) = 0
$$
The general solution to this equation is $\psi(x) = Ae^{ikx}+Be^{-ikx}$. If you now impose that $\psi(0) = \psi(L) = 0$, because we need the function to be zero outside of the box, but we also need it to be continuous, we find that there is a discrete set of possible solutions
$$
\psi_n(x) = \sqrt{\frac{2}{L}}\sin\Big(\frac{n\pi x}{L}\Big)
$$
each with associated energy $E_n = n^2 \Big(\frac{\pi^2 \hbar^2}{2mL^2}\Big)$.
We found this solution by solving the TISE both outside and inside the box and by accepting only the continuous solutions. These are all the stationary solutions to this problem, namely each solution of this kind will not evolve if you neglect a global phase. In general you have also non-stationary solutions, which will evolve according to the TDSE, but each of them has to be written as a linear combination of $\psi_n(x) = \sqrt{\frac{2}{L}}\sin\Big(\frac{n\pi x}{L}\Big)$ and therefore will have to be continuous and vanish at the borders.
This means that not all the wave functions are permitted in a problem like this and only those which can be written as a linear combination of the $\psi_n(x)$ are physically possible. For a general initial condition
$$
\psi(x, 0) = \sum_n c_n \psi_n(x)
$$
The evolution is found by solving the TDSE and gives
$$
\psi(x, t) = \sum_n c_n \psi_n(x)e^{-i\frac{E_n}{\hbar}t}
$$