> For the complete documentation index, see [llms.txt](https://datalab-docs.datacamp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://datalab-docs.datacamp.com/work/code-cell.md).

# Code cell

Use a code cell to write, run and inspect code and add it to your notebook.

### Writing code

* Write code like you would do in any other coding environment!
* You will get code suggestions while you type, so you don't have to type long function or variables names in full.

### Running code

To run code:

* Use "Run" in the cell menu or `Ctrl` + `Enter` to run the currently active code cell.
* Use `Shift` + `Enter` to run the currently active code cell and make the next cell in the notebook active.

#### Code cell status

There is a 'stoplight' dot on the top-right hand side of your workbook with different states:

![](https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FJuz0qYNV5HUkZuTkEhWp%2Fimage.png?alt=media\&token=71ab2789-3921-47c3-b1cc-fe8410931942)&#x20;

The cell successfully ran, and the code in the cell hasn't changed since.

![](https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FzsfgfpoJxseF32z5MCzj%2Fimage.png?alt=media\&token=2c2a7cad-9380-44b6-89b8-ef911e2cb45c)

The cell successfully ran before, but since then the code has changed, so the cell output may be stale.

![](https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FazSnOgvLR8rlpOz9wmJt%2Fimage.png?alt=media\&token=84d346a5-8754-4a1d-8f25-b1ff41d15c8d)

The code cell is in the process of (re)running

![](https://4179539225-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MZqboFGZzD87nn7oPsm%2Fuploads%2FbJoaUYh4iHa4WjiE0xEy%2Fimage.png?alt=media\&token=099de53a-ea88-40df-b6cc-9ddc164aade2)

The cell failed to execute successfully because of an error.

### Inspect results

* If your code prints out text, data frames or charts, these will appear below the code cell.
* If your code generates several printouts, these will appear below the code cell one after the other.

### Workbook language = code cell language

If you're in a Python workbook, you can only write Python code; if you're in an R workbook, you can write only Python code. If you want to work with the other language, you have to create a new workbook in that language.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://datalab-docs.datacamp.com/work/code-cell.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
