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

# Expose a web service

> Start a server in your sandbox and share it through a public HTTPS URL.

Start a server in the background, then expose its listening port:

```python theme={null}
from lithosbox import LithosBox

box = LithosBox()
sandbox = box.sandboxes.create()
sandbox.files.write("/work/site/index.html", "<h1>Hello from LithosBox</h1>")
sandbox.run(
    "python3 -m http.server 8000 --bind 0.0.0.0 --directory /work/site "
    "> /work/server.log 2>&1",
    background=True,
).check()

endpoint = sandbox.expose(8000)
print(endpoint.url)
```

Open the printed URL in your browser. It serves your application once the server
is listening. The URL uses HTTPS even though the example server listens on HTTP
inside the sandbox.

## Configure your application

Make your server listen on `0.0.0.0`, and pass that same port to `expose()`. Keep
long-lived servers in the background so starting one does not block your SDK call.

Anyone with the URL can reach the service. Add authentication in your application
before using the endpoint for private data or actions.

The endpoint supports HTTP/1.1 and HTTP/2. HTTP/1.0 requests receive `426`.

## Check a server that does not respond

Read the application's log:

```python theme={null}
print(sandbox.files.read("/work/server.log"))
```

Check that the process is running and listening on the port you exposed. If the
sandbox is paused or archived, resume or unarchive it before trying again.

A server keeps its sandbox awake while active. After archive/unarchive, keep using
the same URL, but allow a brief reconnect period. Existing network connections
need to be established again.

## Remove the endpoint

Remove public access without deleting the sandbox:

```python theme={null}
box.ingress.delete(endpoint.id)
```

You can inspect a sandbox's endpoints in the console or with
[`GET /vms/{id}/ingress`](/reference/http-api#public-endpoints).

When you no longer need the server or its sandbox:

```python theme={null}
sandbox.delete()
box.close()
```

Deleting the sandbox also makes its endpoints unavailable. Clients may take up to
about 30 seconds to receive a failed connection rather than wait for a response.
