> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions

> Where a workspace keeps its sessions, in memory, on disk, on Redis or in an S3 bucket.

The sessions store keeps each session's shell state and the workspace's own
record:

* Each session's working directory, variables, functions, mount modes and
  [profile](https://docs.mirage.strukto.ai/home/configuration/session.md) rules. Shell options and the last exit status
  stay with the running instance.
* Which sessions the workspace has, and which one is the default.

A workspace built again under the same id finds its sessions where it left
them, and every instance of the workspace on the same store shares them.

| `type` | Keeps them | Keys |
| - | - | - |
| `ram` | In the process's memory, until it exits | |
| `disk` | In files under `root` | `root`, default `~/.mirage/state` |
| `redis` | On Redis, under `key_prefix` and the workspace id | `url`, `key_prefix`, default `mirage:` |
| `s3` | In a bucket, under `key_prefix` and the workspace id | The [S3 config fields](https://docs.mirage.strukto.ai/home/setup/s3.md), `key_prefix`, default `mirage/` |

The group key is `store.sessions`. It is the only store that takes `s3`, so
`s3` goes on this key, never on `store.type`.

Set `store.type` as well. A `store` block without it keeps the other
stores in memory, even on a server: the server keeps them on disk only
when the config has no `store` block. The examples below set
`type: disk`, which matches that default.

## On disk

> [tab] YAML
>
> ```yaml theme={null}
> workspace_id: agent
> store:
>   type: disk
>   sessions:
>     type: disk
>     root: /var/lib/mirage
> ```

> [tab] Python
>
> ```python theme={null}
> from mirage import Workspace
> from mirage.workspace.store import DiskWorkspaceStateStore
>
> store = DiskWorkspaceStateStore(
>     sessions=DiskWorkspaceStateStore(root="/var/lib/mirage"),
> )
> ws = Workspace(mounts, workspace_id="agent", store=store, owns_store=True)
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { DiskWorkspaceStateStore, Workspace } from '@struktoai/mirage-node'
>
> const store = new DiskWorkspaceStateStore({
>   sessions: new DiskWorkspaceStateStore({ root: '/var/lib/mirage' }),
> })
> const ws = new Workspace(mounts, { workspaceId: 'agent', store, ownsStore: true })
> ```

## On Redis

> [tab] YAML
>
> ```yaml theme={null}
> workspace_id: agent
> store:
>   type: disk
>   sessions:
>     type: redis
>     url: redis://redis.internal:6379/0
> ```

> [tab] Python
>
> ```python theme={null}
> from mirage import Workspace
> from mirage.workspace.store import DiskWorkspaceStateStore, RedisWorkspaceStateStore
>
> store = DiskWorkspaceStateStore(
>     sessions=RedisWorkspaceStateStore(url="redis://redis.internal:6379/0"),
> )
> ws = Workspace(mounts, workspace_id="agent", store=store, owns_store=True)
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { DiskWorkspaceStateStore, RedisWorkspaceStateStore, Workspace } from '@struktoai/mirage-node'
>
> const store = new DiskWorkspaceStateStore({
>   sessions: new RedisWorkspaceStateStore({ url: 'redis://redis.internal:6379/0' }),
> })
> const ws = new Workspace(mounts, { workspaceId: 'agent', store, ownsStore: true })
> ```

## In an S3 bucket

The block takes the same fields as an [S3 mount](https://docs.mirage.strukto.ai/home/setup/s3.md), so
credentials and an `endpoint_url` for an S3-compatible store go here too.

> [tab] YAML
>
> ```yaml theme={null}
> workspace_id: agent
> store:
>   type: disk
>   sessions:
>     type: s3
>     bucket: agent-state
>     region: us-east-1
> ```

> [tab] Python
>
> ```python theme={null}
> from mirage import Workspace
> from mirage.vfs.s3 import S3Config
> from mirage.workspace.store import DiskWorkspaceStateStore, S3WorkspaceStateStore
>
> store = DiskWorkspaceStateStore(
>     sessions=S3WorkspaceStateStore(S3Config(bucket="agent-state", region="us-east-1")),
> )
> ws = Workspace(mounts, workspace_id="agent", store=store, owns_store=True)
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { DiskWorkspaceStateStore, S3WorkspaceStateStore, Workspace } from '@struktoai/mirage-node'
>
> const store = new DiskWorkspaceStateStore({
>   sessions: new S3WorkspaceStateStore({ bucket: 'agent-state', region: 'us-east-1' }),
> })
> const ws = new Workspace(mounts, { workspaceId: 'agent', store, ownsStore: true })
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.