In this paper, we report a flame deposition method to prepare carbon nanoparticles (CNPs) from coconut oil. The CNPs were further modified with a piranha solution to obtain surface-carboxylated carbon nanoparticles (c-CNPs). When used as an anode for sodium-ion batteries, the CNPs and c-CNPs respectively delivered discharge capacities of 277 and 278mAhg−1 in the second cycle at a current density of 100mAg−1. At the 20th cycle, the capacities of CNP and c-CNPs were 217 and 206mAhg−1 respectively. The results suggest that modification of the CNPs with the piranha solution improved neither the charge storage capacity nor the stability against cycling in a sodium-ion battery. When the CNP and c-CNP were used an anode in a lithium-ion battery, 2nd-cycle discharge capacities of 741 and 742mAhg−1 respectively at a current density of 100mAg−1 were obtained. After 20 cycles the capacities of CNP and c-CNP became 464 and 577mAhg−1 respectively, showing the cycling stability of the CNPs was improved after modification. The excellent cycling performance, high capacity and good rate capability make the present material as highly promising anodes for both sodium-ion and lithium-ion batteries.