---
layout: "docs"
page_title: "Runtime Environment"
sidebar_current: "docs-jobspec-environment"
description: |-
Learn how to configure the Nomad runtime environment.
---
# Runtime Environment
Some settings you specify in your [job specification](/docs/jobspec/) are passed to tasks
when they start. Other settings are dynamically allocated when your job is
scheduled. Both types of values are made available to your job through
environment variables.
## Summary
Variable |
Description |
NOMAD_ALLOC_DIR |
Path to the shared alloc directory |
NOMAD_TASK_DIR |
Path to the local task directory |
NOMAD_MEMORY_LIMIT |
The task's memory limit in MB |
NOMAD_CPU_LIMIT |
The task's CPU limit in MHz |
NOMAD_ALLOC_ID |
The allocation ID of the task |
NOMAD_ALLOC_NAME |
The allocation name of the task |
NOMAD_ALLOC_INDEX |
The allocation index; useful to distinguish instances of task groups |
NOMAD_TASK_NAME |
The task's name |
NOMAD_IP_"label" |
The IP of the the port with the given label |
NOMAD_PORT_"label" |
The port value with the given label |
NOMAD_ADDR_"label" |
The IP:Port pair of the the port with the given label |
NOMAD_HOST_PORT_"label" |
The host port for the given label if the port is port mapped |
NOMAD_META_"key" |
The metadata of the task |
## Task Identifiers
Nomad will pass both the allocation ID and name as well as the task's name.
These are given as `NOMAD_ALLOC_ID`, `NOMAD_ALLOC_NAME`, `NOMAD_ALLOC_INDEX` and
`NOMAD_TASK_NAME`. The allocation ID and index can be useful when the task being
run needs a unique identifier or to know its instance count.
## Resources
When you request resources for a job, Nomad creates a resource offer. The final
resources for your job are not determined until it is scheduled. Nomad will
tell you which resources have been allocated after evaluation and placement.
### CPU and Memory
Nomad will pass CPU and memory limits to your job as `NOMAD_CPU_LIMIT` and
`NOMAD_MEMORY_LIMIT`. Your task should use these values to adapt its behavior to
fit inside the resource allocation that nomad provides. For example, you can use
the memory limit to inform how large your in-process cache should be, or to
decide when to flush buffers to disk.
Both CPU and memory are presented as integers. The unit for CPU limit is
`1024 = 1Ghz`. The unit for memory is `1 = 1 megabytes`.
Writing your applications to adjust to these values at runtime provides greater
scheduling flexibility since you can adjust the resource allocations in your
job specification without needing to change your code. You can also schedule workloads
that accept dynamic resource allocations so they can scale down/up as your
cluster gets more or less busy.
### Networking
Nomad assigns IPs and ports to your jobs and exposes them via environment
variables. See the [Networking](/docs/jobspec/networking.html) page for more
details.
### Task Directories