With the wearable electronics progressing rapidly, the demand for flexible, long-life and low-cost electrodes of Li-ion batteries (LIBs) becomes more and more urgent. Due to the abundant resources and low cost, silica (SiO2), especially the amorphous one, has attracted a lot of interests on the application of anode materials for LIBs. However, SiO2 still suffer from the poor cycling performance mainly caused by the huge volume change during cycling like other alloy-type materials. Furthermore, it remains a challenge to fabricate the SiO2–based flexible electrode. Herein, we propose a facile in situ strategy to fabricate the electrospun robust free-standing SiO2/carbon nanofibers (denoted as in-SCNFs) film constructed by N-doped carbon nanofibers encapsulating uniformly amorphous SiO2 nanoparticles. The in situ synthesized finer SiO2 nanoparticles in the in-SCNFs are uniformly encapsulated in flexible carbon nanofibers, which can effectively buffer the volume change. Furthermore, the robust in-SCNFs film possesses the excellent mechanical flexibility and strength. So, when served as the free-standing anode of LIBs, the in-SCNFs film exhibits superior cycling performance. A discharge specific capacity of 405mAh/g can be delivered even after a long-term 1000 cycles at a large current density of 500mA/g, and the retention is up to 115%. It is an exciting finding that the in-SCNFs film is also a long-life anode of Na-ion batteries (NIBs). The 99% of initial capacity can be kept after 250 cycles at 500mA/g. To our best knowledge, this is the first report on the application of SiO2/C composite for NIBs. These results suggest that the as-fabricated in-SCNFs film can become one promising free-standing long-life anode for LIBs and NIBs.