The dynamics of a conducting fluid or plasma are extremely complex; distinct time and spatial scales are involved and usually they are separated by several orders of magnitude. To describe these dynamics we can use a hydrodynamic fluid approach that couples the magnetic field motion, it is called the magnetohydrodynamic (MHD) model. The MHD system of equations can be used to describe astrophysical as well as plasma experimental setups. In particular we have used the MHD model to study the confinement of fusion plasmas in laboratory devices. A novel penalization technique implemented in a pseudo-spectral Fourier code allows a fast geometry modification of the plasma container. Three-dimensional nonlinear simulations are run to study the different dynamics appearing inside the modified vessel. The investigation of the plasma dynamics is essential to understand and to improve the confinement in plasma fusion machines. In some configurations a linear stability analysis can be performed. In these cases a simplified form of the MHD equations is used. We show that for edge plasma instabilities a linear MHD theory can be applied and it reproduces successfully experimental observations.