> ## 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/profiles.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.workspace`. It is the only store that takes `s3`, so
`s3` goes on this key, never on `store.type`.

## On disk

**YAML**

```yaml theme={null}
workspace_id: agent
store:
  workspace:
    type: disk
    root: /var/lib/mirage
```

**Python**

```python theme={null}
from mirage import Workspace
from mirage.workspace.store import DiskWorkspaceStateStore, RAMWorkspaceStateStore

store = RAMWorkspaceStateStore(
    workspace=DiskWorkspaceStateStore(root="/var/lib/mirage"),
)
ws = Workspace(mounts, workspace_id="agent", store=store, owns_store=True)
```

**TypeScript**

```typescript theme={null}
import { DiskWorkspaceStateStore, RAMWorkspaceStateStore, Workspace } from '@struktoai/mirage-node'

const store = new RAMWorkspaceStateStore({
  workspace: new DiskWorkspaceStateStore({ root: '/var/lib/mirage' }),
})
const ws = new Workspace(mounts, { workspaceId: 'agent', store, ownsStore: true })
```

## On Redis

**YAML**

```yaml theme={null}
workspace_id: agent
store:
  workspace:
    type: redis
    url: redis://redis.internal:6379/0
```

**Python**

```python theme={null}
from mirage import Workspace
from mirage.workspace.store import RAMWorkspaceStateStore, RedisWorkspaceStateStore

store = RAMWorkspaceStateStore(
    workspace=RedisWorkspaceStateStore(url="redis://redis.internal:6379/0"),
)
ws = Workspace(mounts, workspace_id="agent", store=store, owns_store=True)
```

**TypeScript**

```typescript theme={null}
import { RAMWorkspaceStateStore, RedisWorkspaceStateStore, Workspace } from '@struktoai/mirage-node'

const store = new RAMWorkspaceStateStore({
  workspace: 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.

**YAML**

```yaml theme={null}
workspace_id: agent
store:
  workspace:
    type: s3
    bucket: agent-state
    region: us-east-1
```

**Python**

```python theme={null}
from mirage import Workspace
from mirage.vfs.s3 import S3Config
from mirage.workspace.store import RAMWorkspaceStateStore, S3WorkspaceStateStore

store = RAMWorkspaceStateStore(
    workspace=S3WorkspaceStateStore(S3Config(bucket="agent-state", region="us-east-1")),
)
ws = Workspace(mounts, workspace_id="agent", store=store, owns_store=True)
```

**TypeScript**

```typescript theme={null}
import { RAMWorkspaceStateStore, S3WorkspaceStateStore, Workspace } from '@struktoai/mirage-node'

const store = new RAMWorkspaceStateStore({
  workspace: 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.