The piston system (particles in a box) is the simplest and paradigmatic model in traditional thermodynamics. However, the recently established framework of stochastic thermodynamics (ST) fails to apply to this model system due to the embedded singularity in the potential. In this Letter we study the stochastic thermodynamics of a particle in a box by adopting a novel coordinate transformation technique. Through comparing with the exact solution of a breathing harmonic oscillator, we obtain analytical results of work distribution for an arbitrary protocol in the linear response regime, and verify various predictions of the Fluctuation-Dissipation Relation. When applying to the Brownian Szilard's engine model, we obtain the optimal protocol λt = λ02 t/τ for a given sufficiently long total time τ . Our study not only establishes a paradigm for studying ST of a particle in a box, but also bridges the long-standing gap in the development of ST.PACS numbers: 05.70. Ln, 05.10.Gg Introduction.-When opening any textbook of thermodynamics [1], the piston system [2], or the classical ideal gas inside a rigid-wall potential is the simplest and an archetypal model used to illustrate various thermodynamic processes and cycles. In the context of traditional thermodynamics, due to the macroscopic size of the system, fluctuations are usually vanishingly small. There work and heat are phenomenological variables and the microscopic equation of motion (EOM) is not directly relevant.When considering a small system, however, fluctuations become important and the EOM becomes essential [3]. In recent years, substantial developments in the field of nonequilibrium thermodynamics in small systems [4] have been made. One of them is the formulation of the so-called stochastic thermodynamics (ST) [5][6][7], where stochastic dynamics is incorporated into thermodynamics. For small systems, e.g., a Brownian particle in a controllable potential, a coherent framework of thermodynamics at the trajectory level is constructed. Fluctuating thermodynamic variables, such as work, heat and entropy production, are identified as functionals of individual trajectories [8][9][10][11], based on which one can in principle calculate their distributions in arbitrary driven processes [12,13], and thus go beyond the traditional thermodynamics. In the linear response regime, the work distribution is Gaussian and satisfies the FluctuationDissipation relations (FDRs) [12,14]. What is more, even in arbitrarily far from equilibrium processes, some exact fluctuation relations concerning work, heat and entropy production are discovered [10,[15][16][17][18][19][20]. Experimentally, these fluctuation relations have been verified in various systems including a Brownian particle in a soft-wall potential [21][22][23][24], exemplified by a charged colloidal particle trapped by an optical tweezer. The essential point of these developments in thermodynamics is the microscopic definition of work, heat and entropy at the trajectory level.However, the usual microscopic definiti...