Skip to content

Commit

Permalink
improvement: allow sandbox flag (#57)
Browse files Browse the repository at this point in the history
* improvement: allow sandbox flag

* improvement: allow sandbox flag
  • Loading branch information
mscolnick authored Nov 18, 2024
1 parent 14d5cd0 commit 09c23c9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can configure the extension using the following settings:

- `marimo.browserType`: Browser to open marimo app (`system` or `embedded`, default: `embedded`)
- `marimo.port`: Default port for marimo server (default: `2818`)
- `marimo.sandbox`: Always start marimo in a sandbox, e.g. `marimo edit --sandbox` (default: `false`). Requires [`uv`](https://docs.astral.sh/uv/) to be installed.
- `marimo.host`: Hostname for marimo server (default: `localhost`)
- `marimo.https`: Enable HTTPS for marimo server (default: `false`)
- `marimo.enableToken`: Enable token authentication (default: `false`)
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@
"default": "localhost",
"description": "The hostname to use for the marimo server."
},
"marimo.sandbox": {
"type": "boolean",
"default": false,
"description": "Whether to always start marimo in a sandbox. Requires `uv` to be installed."
},
"marimo.https": {
"type": "boolean",
"default": false,
Expand Down
9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Config {
readonly enableToken: boolean;
readonly tokenPassword: string | undefined;
readonly https: boolean;
readonly sandbox: boolean;
}

/**
Expand Down Expand Up @@ -122,6 +123,14 @@ export const Config = {
get showTerminal(): boolean {
return getConfig("showTerminal", false);
},

/**
* Whether to always start marimo in sandbox mode.
* @default false
*/
get sandbox(): boolean {
return getConfig("sandbox", false);
},
};

export async function composeUrl(port: number): Promise<string> {
Expand Down
1 change: 1 addition & 0 deletions src/services/server-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export class ServerManager implements IServerManager {
.headless(true)
.enableToken(this.config.enableToken)
.tokenPassword(this.config.tokenPassword)
.sandbox(this.config.sandbox)
.build();
}

Expand Down
16 changes: 16 additions & 0 deletions src/utils/__tests__/cmd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ describe("MarimoCmdBuilder", () => {
`"marimo --yes edit path/to/file --host=0.0.0.0 --port=2718 --headless --no-token"`,
);
});

it("should support sandbox mode", () => {
const cmd = new MarimoCmdBuilder()
.debug(false)
.mode("edit")
.fileOrDir("path/to/file")
.host("localhost")
.port(2718)
.headless(true)
.enableToken(false)
.sandbox(true)
.build();
expect(cmd).toMatchInlineSnapshot(
`"marimo --yes edit path/to/file --host=localhost --port=2718 --headless --no-token --sandbox"`,
);
});
});
7 changes: 7 additions & 0 deletions src/utils/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export class MarimoCmdBuilder {
return this;
}

sandbox(value: boolean) {
if (value) {
this.cmd.push("--sandbox");
}
return this;
}

build() {
return this.cmd.join(" ");
}
Expand Down

0 comments on commit 09c23c9

Please sign in to comment.