Kaggle Code Notebooks: GPU Selection, Internet Access, and Ephemeral Storage
Save model checkpoints to /kaggle/working/, enable internet only when allowed, and verify GPU before training in Kaggle Code notebooks.
22 Feb 2026, 00:01 UTC

You can lose a trained model when the Kaggle session ends
You start a training run in a Kaggle Code notebook, close the browser, and return to find the model checkpoint is gone. The notebook is saved, but files written to the container's default directories are not. Kaggle Code containers are ephemeral: only /kaggle/working/ survives between sessions. Internet access is also disabled by default for competition notebooks, so a script that downloads a dataset can fail with a connection error even when the code is correct.
Before you run anything, set the hardware accelerator in Notebook Settings, write checkpoints and outputs to /kaggle/working/, enable internet access only when competition rules allow it, and treat your Kaggle API token like a password--never paste it into a public notebook.
What persists and what disappears
Kaggle Code runs Python or R notebooks in a container. You choose CPU, GPU, or TPU in the notebook's Settings panel before execution starts. That choice cannot be changed while a run is active; if the accelerator is unavailable, stop the session and restart with different hardware settings. The container filesystem is wiped when the session ends, except for /kaggle/working/, which is attached to the notebook version history. Cell output and logs are size-capped, so verbose training loops can be truncated.
Worked configuration: verify GPU and save to persistent storage
Run this in a Kaggle Code notebook cell:
import os
import tensorflow as tf
# Verify GPU availability in the current container
gpus = tf.config.list_physical_devices('GPU')
print("GPUs detected:", len(gpus))
# Train or load a model here, then save to the persistent directory
model_path = "/kaggle/working/checkpoint_epoch_5.h5"
model.save(model_path)
print("Saved to", model_path, "size:", os.path.getsize(model_path), "bytes")
Where to run: Kaggle Code notebook cell. Permissions: none special; the cell runs under your Kaggle account. Expected check: the cell prints the number of physical GPUs visible to TensorFlow. Risk: If you selected CPU in Settings, TensorFlow reports zero GPUs. You must stop the session, open Settings, choose GPU, and rerun.
For a shell-level check inside the same container, prefix a cell with !:
!nvidia-smi
This executes in the container shell, not your local terminal. When a GPU is allocated, the command prints a table with the GPU name and memory usage. If the command is not found or returns no devices, the hardware setting did not apply.
Controlling internet access
Internet is disabled by default for competition notebooks to reduce data-leakage risk. In Notebook Settings, toggle "Internet access" on. This is subject to the competition's external-data policy and Kaggle's terms. Using it to retrieve labels or solutions for an active competition can violate the rules and result in disqualification. For non-competition notebooks, internet access is generally permitted but still governed by Kaggle's terms.
Using the Kaggle API from your local machine
To download datasets or submit entries from outside Kaggle, install the CLI in your local terminal:
pip install kaggle
Place your API token at ~/.kaggle/kaggle.json on Linux or macOS, or %USERPROFILE%\.kaggle\kaggle.json on Windows. The file contains:
{
"username": "",
"key": ""
}
Where to run: your local terminal, not a Kaggle notebook cell. Permissions: restrict the token file so only you can read it. On Unix:
chmod 600 ~/.kaggle/kaggle.json
Expected check: kaggle --version prints the CLI version, and kaggle datasets list returns datasets accessible to your account.
Risk: If you commit kaggle.json to a public repository, rotate the token immediately in your Kaggle account settings. Never hardcode KAGGLE_USERNAME or KAGGLE_KEY in a notebook you publish.
Limits and common mistakes
- Saving outside
/kaggle/working/: Files in/tmp, the current working directory, or other container paths disappear when the session ends. Only/kaggle/working/is versioned with the notebook. - Changing hardware mid-run: GPU/TPU selection is fixed once execution starts. Stop and restart to change it.
- Idle session reclamation: Long jobs without output can be reclaimed. Checkpoint frequently to
/kaggle/working/and export large artifacts to Kaggle Datasets or Models. - Output caps: Excessive
print()output or large DataFrame displays can be truncated. Write large results to files in/kaggle/working/instead of printing them. - Internet in competitions: Enabling internet does not override competition rules. Verify the external-data policy before downloading anything.
Verification checklist
- Open the notebook's Settings panel and confirm the Hardware dropdown shows GPU or TPU options.
- Run
nvidia-smiortf.config.list_physical_devices('GPU')in a cell to confirm the accelerator is attached. - Create a test file in
/kaggle/working/, stop the session, reopen the notebook, and confirm the file still appears. - Run
kaggle --versionandkaggle datasets listlocally with a valid token to confirm CLI access.
Limitations
GPU and TPU slots are shared and may be queued during peak times. There is no guaranteed way to reserve an accelerator. This guide covers Kaggle Code behavior as generally documented; specific competition rules can override internet access permissions, so check each competition page before enabling it.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.