Worldline formalism for a confined scalar field