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

# リモート関数

> 自動シリアライズを利用して、サンドボックス内で Python 関数を実行します。

<Note>
  The examples on this page omit `auth`. To authenticate with your W\&B API key, install `cwsandbox[wandb]` and pass `auth=AuthStrategy.WANDB` to `Sandbox.run()`, `Sandbox()`, or `Sandbox.session()`. See [Get started](/products/sandboxes/serverless/get-started).
</Note>

This tutorial shows you how to run Python functions inside a sandbox using remote functions. You can call sandbox-executed code as if it were a local function instead of constructing shell command strings. It's for developers who want to invoke compute in a sandbox directly from their Python code and collect typed results.

## Define and call a remote function

Decorate a function with `@session.function()` to call it inside the sandbox with `.remote()`. The call returns a reference you resolve with `.result()`:

```python theme={"system"}
from cwsandbox import Sandbox, SandboxDefaults

with Sandbox.session(SandboxDefaults()) as session:
    @session.function()
    def add(x: int, y: int) -> int:
        return x + y

    result = add.remote(2, 3).result()  # 5
```

## Run functions in parallel with `.map()`

Use `.map()` to dispatch many invocations at once and collect their results. Independent calls run concurrently instead of one at a time:

```python theme={"system"}
@session.function()
def square(x: int) -> int:
    return x * x

refs = square.map([(1,), (2,), (3,)])
results = [r.result() for r in refs]  # [1, 4, 9]
```

## Next steps

You can now invoke Python functions inside a sandbox as if they were local calls, and fan out work in parallel with `.map()`.

For serialization modes, `.local()` testing, and more, see the [Remote functions guide](../guides/remote-functions).
