# User and working directory
<subtitle>Default user and working directory in sandboxes and templates</subtitle>

The default user in the template is `user`, and the default working directory is `/home/user` (the user's home directory). This is different from the Docker defaults, where the default user is `root` and the default working directory is `/`. This is done to facilitate tool installation and improve default security.

The last user and working directory set in the template will be persisted as the default values ​​for sandbox execution. The following is an example of setting the user and working directory in the template definition.

## Default user and working directory in the sandbox

```python
sbx = Sandbox.create()
sbx.commands.run("whoami")  # user
sbx.commands.run("pwd")  # /home/user
```

## Custom user and working directory templates

```python
# template.py
template = (
    Template()
    .from_base_image()
    .run_cmd("whoami")  # user
    .run_cmd("pwd")  # /home/user
    .set_user("guest")
    .run_cmd("whoami")  # guest
    .run_cmd("pwd")  # /home/guest
)

# build.py
Template.build(template, 'custom-user-template',
    on_build_logs=default_build_logger()
)

# main.py
sbx = Sandbox.create("custom-user-template")
sbx.commands.run("whoami")  # guest
sbx.commands.run("pwd")  # /home/guest
```
