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

# Muse Code

> Run Muse Code in a secure E2B sandbox with full filesystem, terminal, and git access.

[Muse Code](https://dev.meta.ai/docs/muse-code) is Meta's coding agent for the terminal and CI, built on Muse Spark. E2B provides a pre-built `muse` template with Muse Code already installed.

## CLI

Create a sandbox with the [E2B CLI](https://docs.e2b.dev/cli.md).

```bash theme={"theme":"css-variables"}
e2b sbx create muse
```

Once inside the sandbox, start Muse Code.

```bash theme={"theme":"css-variables"}
muse
```

## Run headless

Use `muse exec` for non-interactive mode and `--yolo` to skip approval prompts, disable Muse Code's own OS sandbox, and trust the workspace. The E2B sandbox is the isolation boundary here, so Muse Code's built-in sandbox is not needed. The sandbox isolates the agent from your host machine, but sandboxes can reach the open internet by default; restrict outbound traffic with [network rules](https://docs.e2b.dev/network/internet-access.md). Muse Code authenticates with an API key from the [Meta Model API dashboard](https://dev.meta.ai) via the `META_API_KEY` environment variable.

> [!NOTE]
>
> Auto-approving tool calls is contained by the sandbox: the agent cannot touch your host machine, local files, or credentials. It can still make outbound network requests, since internet access is enabled by default. To limit where an auto-approved agent can connect, configure [outbound network rules](https://docs.e2b.dev/network/internet-access.md) (`allowInternetAccess`, plus allow/deny lists by CIDR or hostname). Hostname rules apply to HTTP(S) traffic only; use CIDR rules for other protocols.

```typescript JavaScript & TypeScript theme={"theme":"css-variables"}
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('muse', {
  envs: { META_API_KEY: process.env.META_API_KEY },
})

const result = await sandbox.commands.run(
  `muse exec --yolo "Create a hello world HTTP server in Go"`
)

console.log(result.stdout)
await sandbox.kill()
```

```python Python theme={"theme":"css-variables"}
import os
from e2b import Sandbox

sandbox = Sandbox.create("muse", envs={
    "META_API_KEY": os.environ["META_API_KEY"],
})

result = sandbox.commands.run(
    'muse exec --yolo "Create a hello world HTTP server in Go"',
)

print(result.stdout)
sandbox.kill()
```

Add `--json` to emit machine-readable JSONL events instead of plain text, and `--max-model-steps` to cap a run that would otherwise loop.

### Example: work on a cloned repository

```typescript JavaScript & TypeScript theme={"theme":"css-variables"}
import { Sandbox } from 'e2b'

const sandbox = await Sandbox.create('muse', {
  envs: { META_API_KEY: process.env.META_API_KEY },
  timeoutMs: 600_000,
})

await sandbox.commands.run(
  'git clone --depth 1 https://x-access-token:$GITHUB_TOKEN@github.com/<owner>/<repo>.git /home/user/repo',
  { envs: { GITHUB_TOKEN: process.env.GITHUB_TOKEN } }
)

const result = await sandbox.commands.run(
  `cd /home/user/repo && muse exec --yolo "Add error handling to all API endpoints"`,
  { onStdout: (data) => process.stdout.write(data) }
)

const diff = await sandbox.commands.run('cd /home/user/repo && git diff')
console.log(diff.stdout)

await sandbox.kill()
```

```python Python theme={"theme":"css-variables"}
import os
from e2b import Sandbox

sandbox = Sandbox.create("muse", envs={
    "META_API_KEY": os.environ["META_API_KEY"],
}, timeout=600)

sandbox.commands.run(
    "git clone --depth 1 https://x-access-token:$GITHUB_TOKEN@github.com/<owner>/<repo>.git /home/user/repo",
    envs={"GITHUB_TOKEN": os.environ["GITHUB_TOKEN"]},
)

result = sandbox.commands.run(
    'cd /home/user/repo && muse exec --yolo "Add error handling to all API endpoints"',
    on_stdout=lambda data: print(data, end=""),
)

diff = sandbox.commands.run("cd /home/user/repo && git diff")
print(diff.stdout)

sandbox.kill()
```

## Build a custom template

If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-built `muse` template.

```typescript JavaScript & TypeScript theme={"theme":"css-variables"}
// template.ts
import { Template } from 'e2b'

export const template = Template()
  .fromTemplate('muse')
```

```python Python theme={"theme":"css-variables"}
# template.py
from e2b import Template

template = (
    Template()
    .from_template("muse")
)
```

```typescript JavaScript & TypeScript theme={"theme":"css-variables"}
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as museTemplate } from './template'

await Template.build(museTemplate, 'my-muse', {
  cpuCount: 2,
  memoryMB: 2048,
  onBuildLogs: defaultBuildLogger(),
})
```

```python Python theme={"theme":"css-variables"}
# build.py
from e2b import Template, default_build_logger
from template import template as muse_template

Template.build(muse_template, "my-muse",
    cpu_count=2,
    memory_mb=2048,
    on_build_logs=default_build_logger(),
)
```

Run the build script to create the template.

```bash JavaScript & TypeScript theme={"theme":"css-variables"}
npx tsx build.ts
```

```bash Python theme={"theme":"css-variables"}
python build.py
```

## Related guides

> [card] [Sandbox persistence](https://docs.e2b.dev/sandbox/persistence.md)
>
> Auto-pause, resume, and manage sandbox lifecycle

> [card] [SSH access](https://docs.e2b.dev/sandbox/ssh-access.md)
>
> Connect to the sandbox via SSH for interactive sessions
