### Configure Systemd 'oneshot' Service for Setup Tasks Source: https://context7_llms Illustrates how to define a systemd service with `mode: "oneshot"` for tasks that should run once, such as installing dependencies. The example shows an `npm install` command that runs automatically on boot if `wantedBy` is set. ```typescript systemd: { services: [ { name: "install-dependencies", mode: "oneshot", exec: ["npm install"], workdir: "/app", wantedBy: ["multi-user.target"], // Start automatically on boot timeoutSec: 300, }, ], } ``` -------------------------------- ### Install Freestyle Sandboxes with bun Source: https://docs.freestyle.sh/v2/git This command installs the Freestyle Sandboxes package using bun. This package is essential for interacting with the Freestyle Git service. ```bash bun add freestyle-sandboxes@beta ``` -------------------------------- ### Install Freestyle Sandboxes Package Source: https://docs.freestyle.sh/v2/vms This code shows how to install the necessary Freestyle Sandboxes package using npm, pnpm, yarn, or bun. This package is essential for programmatically interacting with Freestyle VMs. ```bash npm i freestyle-sandboxes@beta ``` ```bash pnpm i freestyle-sandboxes@beta ``` ```bash yarn add freestyle-sandboxes@beta ``` ```bash bun add freestyle-sandboxes@beta ``` -------------------------------- ### Get VM Source: https://docs.freestyle.sh/v2/git Retrieves information about a Virtual Machine. ```APIDOC ## POST /API-Reference/vm/get_vm ### Description Retrieves information about a Virtual Machine. ### Method POST ### Endpoint /API-Reference/vm/get_vm ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Details not provided in the input text) ### Request Example (Example not provided in the input text) ### Response #### Success Response (200) (Details not provided in the input text) #### Response Example (Example not provided in the input text) ``` -------------------------------- ### GET /API-Reference/git/handle_list_repositories Source: https://docs.freestyle.sh/v2/serverless/runs Lists repositories with metadata. ```APIDOC ## GET /API-Reference/git/handle_list_repositories ### Description Lists repositories with metadata. ### Method GET ### Endpoint /API-Reference/git/handle_list_repositories ### Parameters #### Path Parameters None #### Query Parameters - **user** (string) - Optional - Filter repositories by username. - **visibility** (string) - Optional - Filter repositories by visibility (e.g., "public", "private"). #### Request Body None ### Request Example ```json { "example": "No request body needed for this operation." } ``` ### Response #### Success Response (200) - **repositories** (array) - A list of repository objects. - **id** (string) - The unique identifier of the repository. - **name** (string) - The name of the repository. - **description** (string) - A brief description of the repository. - **default_branch** (string) - The default branch name. - **visibility** (string) - The visibility of the repository. #### Response Example ```json { "repositories": [ { "id": "repo-12345", "name": "my-awesome-project", "description": "A project to showcase API features.", "default_branch": "main", "visibility": "public" }, { "id": "repo-67890", "name": "private-repo", "description": "Internal project repository.", "default_branch": "develop", "visibility": "private" } ] } ``` ``` -------------------------------- ### Get GitHub Sync Configuration Source: https://docs.freestyle.sh/v2/vms Get the GitHub sync configuration for a repository, if configured. ```APIDOC ## GET /API-Reference/git/get_github_sync ### Description Get the GitHub sync configuration for a repository, if configured. ### Method GET ### Endpoint /API-Reference/git/get_github_sync ### Parameters #### Query Parameters - **repository_id** (string) - Required - The ID of the repository. ### Response #### Success Response (200) - **github_sync** (object) - The GitHub sync configuration details. - **owner** (string) - The owner of the GitHub repository. - **repo** (string) - The name of the GitHub repository. - **last_synced** (string) - The timestamp of the last sync. #### Response Example ```json { "github_sync": { "owner": "freestyle", "repo": "freestyle-repo", "last_synced": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Get Dev Server Configuration Source: https://docs.freestyle.sh/v2/vms Get the dev server configuration for a repository and branch. ```APIDOC ## GET /API-Reference/git/get_dev_server_configuration ### Description Get the dev server configuration for a repository and branch. ### Method GET ### Endpoint /API-Reference/git/get_dev_server_configuration ### Parameters #### Query Parameters - **repository_id** (string) - Required - The ID of the repository. - **branch** (string) - Optional - The name of the branch for which to retrieve the configuration. If not provided, the default branch configuration is retrieved. ### Response #### Success Response (200) - **configuration** (object) - The dev server configuration details. - **port** (integer) - The port number. - **command** (string) - The command to run. #### Response Example ```json { "configuration": { "port": 3000, "command": "npm start" } } ``` ``` -------------------------------- ### GET /API-Reference/git/handle_list_repositories Source: https://docs.freestyle.sh/v2/git Lists repositories with their metadata. ```APIDOC ## GET /API-Reference/git/handle_list_repositories ### Description List repositories with metadata. ### Method GET ### Endpoint /API-Reference/git/handle_list_repositories ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of repositories to return. - **offset** (integer) - Optional - The number of repositories to skip. ### Response #### Success Response (200) - **repositories** (array) - An array of repository objects. - **id** (string) - The unique identifier of the repository. - **name** (string) - The name of the repository. - **default_branch** (string) - The name of the default branch. #### Response Example ```json { "repositories": [ { "id": "repo-1", "name": "Project Alpha", "default_branch": "main" }, { "id": "repo-2", "name": "Project Beta", "default_branch": "develop" } ] } ``` ``` -------------------------------- ### GET /API-Reference/git/handle_list_repositories Source: https://docs.freestyle.sh/v2/serverless/deployments Lists all available repositories with their metadata. ```APIDOC ## GET /API-Reference/git/handle_list_repositories ### Description List repositories with metadata. ### Method GET ### Endpoint /API-Reference/git/handle_list_repositories ### Parameters No parameters required. ### Request Example ```bash GET /API-Reference/git/handle_list_repositories ``` ### Response #### Success Response (200) - **repositories** (array) - An array of repository objects. - **id** (string) - The unique identifier of the repository. - **name** (string) - The name of the repository. - **default_branch** (string) - The name of the default branch. #### Response Example ```json { "repositories": [ { "id": "my-repo-1", "name": "Repository One", "default_branch": "main" }, { "id": "my-repo-2", "name": "Repository Two", "default_branch": "develop" } ] } ``` ``` -------------------------------- ### Install Packages with Bun Runtime Source: https://context7_llms Provides examples of installing npm packages using the Bun runtime within a VM. It covers installing from a package.json, installing specific dependencies, and installing globally or as dev dependencies. ```typescript // Install from package.json in current directory await vm.js.install(); // Install from package.json in specific directory await vm.js.install({ directory: "/app" }); // Install specific packages await vm.js.install({ deps: ["lodash", "express"] }); // Install with specific versions await vm.js.install({ deps: { "lodash": "^4.0.0", "express": "~5.0.0" } }); // Install as dev dependencies await vm.js.install({ deps: ["typescript"], dev: true }); // Install globally await vm.js.install({ global: true, deps: ["typescript"] }); ``` -------------------------------- ### Get File from VM Source: https://docs.freestyle.sh/v2/git Retrieves a file from a Virtual Machine. ```APIDOC ## POST /API-Reference/vm/get_file ### Description Retrieves a file from a Virtual Machine. ### Method POST ### Endpoint /API-Reference/vm/get_file ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Details not provided in the input text) ### Request Example (Example not provided in the input text) ### Response #### Success Response (200) (Details not provided in the input text) #### Response Example (Example not provided in the input text) ``` -------------------------------- ### GET /llmstxt/freestyle_sh_llms-full_txt Source: https://docs.freestyle.sh/v2/serverless/runs Lists all serverless runs associated with the project. ```APIDOC ## GET /llmstxt/freestyle_sh_llms-full_txt ### Description Retrieves a list of all serverless runs initiated within the Freestyle project. ### Method GET ### Endpoint /llmstxt/freestyle_sh_llms-full_txt ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of runs to return. - **offset** (integer) - Optional - The number of runs to skip before starting to collect the result set. ### Response #### Success Response (200) - **runs** (array) - A list of serverless run objects. - **run_id** (string) - The unique identifier for the serverless run. - **status** (string) - The current status of the serverless run. - **created_at** (string) - The timestamp when the run was created. #### Response Example ```json { "runs": [ { "run_id": "run_abc123", "status": "completed", "created_at": "2023-10-27T10:00:00Z" }, { "run_id": "run_def456", "status": "running", "created_at": "2023-10-27T10:05:00Z" } ] } ``` ``` -------------------------------- ### Get a tag object Source: https://docs.freestyle.sh/v2/vms Retrieve a tag object from the Git database. ```APIDOC ## GET /API-Reference/git/handle_get_tag ### Description Get a tag from the Git database. ### Method GET ### Endpoint /API-Reference/git/handle_get_tag ### Parameters #### Path Parameters * **repo_id** (string) - Required - The ID of the repository. * **tag_sha** (string) - Required - The SHA of the tag. ### Request Example ```json { "repo_id": "your_repo_id", "tag_sha": "your_tag_sha" } ``` ### Response #### Success Response (200) - **tag** (string) - The name of the tag. - **message** (string) - The tag message. - **sha** (string) - The SHA of the tag object. - **tagger** (object) - Information about the tagger. #### Response Example ```json { "tag": "v1.0.0", "message": "Release version 1.0.0", "sha": "your_tag_sha", "tagger": { "name": "John Doe", "email": "john.doe@example.com", "date": "2023-01-01T10:00:00Z" } } ``` ``` -------------------------------- ### Get Repository Tree (Java) Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Demonstrates how to get a repository tree object using Java. This is beneficial for Java-based applications that manage or interact with Git repositories. ```java // Java example would go here, showing the HTTP request implementation. ``` -------------------------------- ### Get repository information Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves detailed information about a specific repository. ```APIDOC ## GET /API-Reference/git/handle_get_repo_info ### Description Retrieve information about a specific repository, including its ID, name, and default branch. ### Method GET ### Endpoint /API-Reference/git/handle_get_repo_info ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. ### Response #### Success Response (200) - **id** (string) - The unique identifier of the repository. - **name** (string) - The name of the repository. - **default_branch** (string) - The name of the default branch. ``` -------------------------------- ### Get the contents of a file or directory Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves the contents of a file or directory within a repository. ```APIDOC ## GET /API-Reference/git/handle_get_contents ### Description Get the contents of a file or directory in a repository. ### Method GET ### Endpoint /API-Reference/git/handle_get_contents ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. - **path** (string) - Required - The path to the file or directory within the repository. - **ref** (string) - Optional - The branch or commit SHA to retrieve contents from. Defaults to the repository's default branch. ### Response #### Success Response (200) - **type** (string) - The type of content ('file' or 'dir'). - **name** (string) - The name of the file or directory. - **path** (string) - The path of the file or directory. - **content** (string) - The content of the file (base64 encoded if it's a file), or a list of entries if it's a directory. - **sha** (string) - The SHA of the file or directory. ``` -------------------------------- ### GET /git/v1/repo/{repo_id}/git/trees/{sha} Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a list of files and directories within a specified Git repository at a given SHA. ```APIDOC ## GET /git/v1/repo/{repo_id}/git/trees/{sha} ### Description Retrieves a list of files and directories within a specified Git repository at a given SHA. ### Method GET ### Endpoint /git/v1/repo/{repo_id}/git/trees/{sha} ### Parameters #### Path Parameters - **repo_id** (string) - Required - The unique identifier of the repository. - **sha** (string) - Required - The SHA of the tree to retrieve. ### Request Example ```bash curl -X GET "https://api.freestyle.sh/git/v1/repo/497f6eca-6276-4993-bfeb-53cbbbba6f08/git/trees/string" ``` ### Response #### Success Response (200) - **tree** (array) - An array of tree objects, each containing path, sha, size, and type. - **sha** (string) - The SHA of the tree. #### Response Example ```json { "tree": [ { "path": "string", "sha": "string", "size": 0, "type": "blob" } ], "sha": "string" } ``` ``` -------------------------------- ### Get Repository Tree (Go) Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Implements the retrieval of a repository's tree object in Go. This is suitable for backend services that need to interact with Git repositories. ```go // Go example would go here, showing how to perform the GET request. ``` -------------------------------- ### Get a tag object Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a specific tag object from the Git database. ```APIDOC ## Get a tag object ### Description Retrieves a specific tag object from the Git database. ### Method GET ### Endpoint /API-Reference/git/handle_get_tag ### Parameters This endpoint does not have explicit parameters listed in the provided text. Please refer to the official documentation for details. ### Request Example (No example provided in the source text) ### Response (No specific response details provided in the source text. Please refer to the official documentation for details.) ``` -------------------------------- ### Get Repository Tree (C#) Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Offers a C# solution for retrieving a repository's tree object. This is useful for .NET applications that require Git repository data. ```csharp // C# example would go here, detailing the API interaction. ``` -------------------------------- ### Get Repository Tree (Python) Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Provides a Python implementation for fetching a repository's tree object. This can be used in scripts or applications for Git repository analysis. ```python # Python example would go here, illustrating the API call. ``` -------------------------------- ### Get a tag reference Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a reference to a specific tag in the Git repository, including its name and SHA. ```APIDOC ## GET /API-Reference/git/handle_get_ref_tag ### Description Get a reference to a tag in the Git repository. Returns the ref name and SHA of the tag. ### Method GET ### Endpoint /API-Reference/git/handle_get_ref_tag ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. - **tag_name** (string) - Required - The name of the tag. ### Response #### Success Response (200) - **ref** (string) - The full reference name of the tag (e.g., "refs/tags/v1.0.0"). - **sha** (string) - The SHA of the tag object. ``` -------------------------------- ### List VMs Source: https://docs.freestyle.sh/v2/git Lists all available Virtual Machines. ```APIDOC ## POST /API-Reference/vm/list_vms ### Description Lists all available Virtual Machines. ### Method POST ### Endpoint /API-Reference/vm/list_vms ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Details not provided in the input text) ### Request Example (Example not provided in the input text) ### Response #### Success Response (200) (Details not provided in the input text) #### Response Example (Example not provided in the input text) ``` -------------------------------- ### Get Repository Tree (JavaScript) Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Fetches the tree object for a given repository and SHA using JavaScript. This function can be integrated into web applications to display repository structures. ```javascript // JavaScript example would go here, demonstrating how to make the GET request. ``` -------------------------------- ### Get Repository Tree (cURL) Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves the tree object for a specified repository and SHA. This endpoint is useful for inspecting the contents of a repository at a particular commit. ```shell curl -X GET "https://api.freestyle.sh/git/v1/repo/497f6eca-6276-4993-bfeb-53cbbbba6f08/git/trees/string" ``` -------------------------------- ### Get a commit object Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a commit object from the Git database with detailed information. ```APIDOC ## GET /API-Reference/git/handle_get_commit ### Description Get a commit from the Git database with detailed information. ### Method GET ### Endpoint /API-Reference/git/handle_get_commit ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. - **sha** (string) - Required - The SHA of the commit object to retrieve. ### Response #### Success Response (200) - **sha** (string) - The SHA of the commit. - **commit** (object) - Commit details including author, committer, message, and tree. - **author** (object) - Author information. - **committer** (object) - Committer information. - **message** (string) - The commit message. - **tree** (object) - Information about the tree associated with the commit. ``` -------------------------------- ### Create VM Source: https://docs.freestyle.sh/v2/git Creates a new Virtual Machine. ```APIDOC ## POST /API-Reference/vm/create_vm ### Description Creates a new Virtual Machine. ### Method POST ### Endpoint /API-Reference/vm/create_vm ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Details not provided in the input text) ### Request Example (Example not provided in the input text) ### Response #### Success Response (200) (Details not provided in the input text) #### Response Example (Example not provided in the input text) ``` -------------------------------- ### Install Freestyle Sandboxes with yarn Source: https://docs.freestyle.sh/v2/git This command installs the Freestyle Sandboxes package using yarn. This package is essential for interacting with the Freestyle Git service. ```bash yarn add freestyle-sandboxes@beta ``` -------------------------------- ### Get a blob object Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a blob object from the Git database. The content is always base64 encoded. ```APIDOC ## GET /API-Reference/git/handle_get_blob ### Description Get a blob from the Git database. The contents will always be base64 encoded. ### Method GET ### Endpoint /API-Reference/git/handle_get_blob ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. - **sha** (string) - Required - The SHA of the blob object to retrieve. ### Response #### Success Response (200) - **content** (string) - The base64 encoded content of the blob. - **encoding** (string) - The encoding of the content (e.g., "base64"). - **sha** (string) - The SHA of the blob object. - **size** (integer) - The size of the blob in bytes. ``` -------------------------------- ### Get repository default branch Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves the name of the default branch for a given repository. ```APIDOC ## GET /API-Reference/git/handle_get_default_branch ### Description Get the default branch name for a repository. ### Method GET ### Endpoint /API-Reference/git/handle_get_default_branch ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. ### Response #### Success Response (200) - **name** (string) - The name of the default branch. ``` -------------------------------- ### GET /git/v1/repo/{repo}/git/trees/{hash} Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a tree object from the Git database, including its entries. This endpoint is useful for inspecting the contents of a directory at a specific commit or reference. ```APIDOC ## GET /git/v1/repo/{repo}/git/trees/{hash} ### Description Retrieves a tree object from the Git database, including its entries. This endpoint is useful for inspecting the contents of a directory at a specific commit or reference. ### Method GET ### Endpoint /git/v1/repo/{repo}/git/trees/{hash} ### Parameters #### Path Parameters - **repo** (string) - Required - The repository id. Format: uuid - **hash** (string) - Required - The object's hash ### Response #### Success Response (200) - **sha** (string) - The SHA-1 hash of the tree object. - **url** (string) - The URL to fetch the tree object. - **tree** (array) - An array of objects, where each object represents an entry in the tree. - **path** (string) - The path of the entry within the tree. - **mode** (string) - The file mode of the entry (e.g., '100644' for a blob, '040000' for a subtree). - **type** (string) - The type of the entry ('blob' for a file, 'tree' for a subdirectory). - **sha** (string) - The SHA-1 hash of the entry. - **size** (integer) - The size of the entry in bytes (only for blobs). - **url** (string) - The URL to fetch the entry. #### Response Example ```json { "sha": "a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4", "url": "/git/v1/repo/your-repo-id/git/trees/a1b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4", "tree": [ { "path": "README.md", "mode": "100644", "type": "blob", "sha": "b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5", "size": 1024, "url": "/git/v1/repo/your-repo-id/git/blobs/b2c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5" }, { "path": "src", "mode": "040000", "type": "tree", "sha": "c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5f6", "url": "/git/v1/repo/your-repo-id/git/trees/c3d4e5f67890a1b2c3d4e5f67890a1b2c3d4e5f6" } ] } ``` ``` -------------------------------- ### Get a branch reference Source: https://docs.freestyle.sh/API-Reference/git/handle_get_tree Retrieves a reference to a specific branch in the Git repository, including its name and SHA. ```APIDOC ## GET /API-Reference/git/handle_get_ref_branch ### Description Get a reference to a branch in the Git repository. Returns the ref name and SHA of the branch. ### Method GET ### Endpoint /API-Reference/git/handle_get_ref_branch ### Parameters #### Query Parameters - **repo_id** (string) - Required - The ID of the repository. - **branch_name** (string) - Required - The name of the branch. ### Response #### Success Response (200) - **ref** (string) - The full reference name of the branch (e.g., "refs/heads/main"). - **sha** (string) - The SHA of the branch's latest commit. ``` -------------------------------- ### Create a Virtual Machine Source: https://docs.freestyle.sh/v2/vms This section describes the process of creating a virtual machine (VM) by calling the 'create' command in the 'vms' namespace. The VM is initialized from a default account snapshot and typically takes under 2 seconds to start. ```markdown Calling `create` in the vms namespace will create and start a vm. This VM will be created from the default snapshot configured for your account. This should usually take less than 2 seconds, but your first VM may take long ``` -------------------------------- ### Install Freestyle Sandboxes with pnpm Source: https://docs.freestyle.sh/v2/git This command installs the Freestyle Sandboxes package using pnpm. This package is essential for interacting with the Freestyle Git service. ```bash pnpm add freestyle-sandboxes@beta ``` -------------------------------- ### Install Freestyle Sandboxes with npm Source: https://docs.freestyle.sh/v2/git This command installs the Freestyle Sandboxes package using npm. This package is essential for interacting with the Freestyle Git service. ```bash npm i freestyle-sandboxes@beta ``` -------------------------------- ### Using Resource Instance Methods (TypeScript) Source: https://context7_llms Demonstrates how to use helper instances returned by creation methods to interact with resources. Examples include starting, suspending, and executing commands on a VM, as well as managing identity permissions and tokens. ```typescript // VM instance methods await vm.start(); await vm.suspend(); await vm.exec("npm install"); // Identity instance methods await identity.permissions.vms.create({ vmId }); const { tokens } = await identity.listTokens(); ``` -------------------------------- ### Practical Resource Creation Examples (TypeScript) Source: https://context7_llms Provides practical examples of creating various resources using the Freestyle SDK, including VMs, Git repositories, and identities. It demonstrates proper destructuring of returned values and setting initial configurations. ```typescript // VMs const { vm, vmId, domains } = await freestyle.vms.create({ ports: [{ port: 443, targetPort: 3000 }], }); // Git repos const { repo, repoId } = await freestyle.git.repos.create({ url: "https://github.com/company/repo", }); // Identities with permissions const { identity, identityId } = await freestyle.identities.create(); await identity.permissions.vms.create({ vmId: vmId, }); const { token } = await identity.createToken(); ``` -------------------------------- ### Express.js Server Setup Source: https://docs.freestyle.sh/v2/serverless/deployments Basic setup for an Express.js server, including importing the library and initializing the app. This is a foundational step for creating web applications with Node.js. ```javascript import express from 'express'; const app = express(); app.get('/', (req, res) => { // Route handler }); ``` -------------------------------- ### Install Python Package with npm Source: https://docs.freestyle.sh/v2/vms This snippet shows how to install the '@freestyle-sh/with-python' package using npm. This command is used to integrate Python functionalities into a project managed with npm. ```bash npm i @freestyle-sh/with-python ``` -------------------------------- ### Initializing Virtual Machine Environments Source: https://docs.freestyle.sh/v2/vms/integrations This section illustrates the initialization of different virtual machine environments, including Node.js, Python, and Bun. Each environment is instantiated using its respective class. ```javascript new VmNodeJs() ``` ```javascript new VmPython() ``` ```javascript new VmBun() ``` -------------------------------- ### Advanced VM Creation Source: https://docs.freestyle.sh/v2/vms Shows how to create a VM with additional files, Git repositories, and a specific working directory. ```APIDOC ## POST /v2/vms ### Description Creates a VM with advanced configurations, including adding custom files, cloning Git repositories, and setting a working directory. This allows for more complex and reproducible VM setups. ### Method POST ### Endpoint /v2/vms ### Parameters #### Query Parameters None #### Request Body - **additionalFiles** (object) - Optional - A map of file paths to their content for files to be added to the VM. Example: `{ "/path/to/file": { "content": "file content" } }` - **gitRepos** (array) - Optional - An array of Git repository configurations to clone into the VM. Example: `[ { "repo": "url", "path": "/destination/path" } ]` - **workdir** (string) - Optional - The working directory to set for the VM. ### Request Example ```javascript import { freestyle } from "freestyle-sandboxes"; const { vmId, vm, domains, consoleUrl } = await freestyle.vms.create({ additionalFiles: { "/repo/README.md": { content: "# Hello World", }, }, gitRepos: [ { repo: "https://github.com/freestyle-sh/freestyle-base-nextjs-shadcn", path: "/repo", }, ], workdir: "/repo", }); ``` ### Response #### Success Response (200) - **vmId** (string) - The unique identifier for the created VM. - **vm** (object) - The created VM instance. - **domains** (array) - List of domains associated with the VM. - **consoleUrl** (string) - URL to access the VM's console. #### Response Example ```json { "vmId": "advanced-vm-id", "vm": { ... }, "domains": [], "consoleUrl": "https://console.freestyle.sh/advanced-vm-id" } ``` ``` -------------------------------- ### Install Node.js Integration for Freestyle VMs Source: https://docs.freestyle.sh/v2/vms This command installs the specific package required to enable Node.js runtime within your Freestyle VMs. This allows you to execute Node.js code directly. ```bash npm i @freestyle-sh/with-nodejs ``` -------------------------------- ### Quick Start: Create VM with a Systemd Service Source: https://context7_llms A basic example demonstrating how to create a VM and configure a systemd service to run a Python HTTP server on port 8000. This illustrates the fundamental structure for defining services within the `systemd.services` array. ```typescript import { freestyle } from "freestyle-sandboxes"; const { vm } = await freestyle.vms.create({ systemd: { services: [ { name: "my-web-server", mode: "service", exec: ["python3 -m http.server 8000"], workdir: "/app", }, ], }, }); ``` -------------------------------- ### Project Setup and Configuration Source: https://docs.freestyle.sh/v2/vms This snippet outlines the initial setup and configuration for the Next.js project. It includes details on the repository path and working directory, essential for understanding the project structure and build process. ```shell path: "/repo" workdir: "/repo" ``` -------------------------------- ### List repositories Source: https://docs.freestyle.sh/v2/vms Retrieve a list of repositories with their associated metadata. ```APIDOC ## GET /API-Reference/git/handle_list_repositories ### Description List repositories with metadata. ### Method GET ### Endpoint /API-Reference/git/handle_list_repositories ### Parameters #### Query Parameters * **limit** (integer) - Optional - The maximum number of repositories to return. * **offset** (integer) - Optional - The number of repositories to skip. ### Request Example ```json { "limit": 10, "offset": 0 } ``` ### Response #### Success Response (200) - **repositories** (array) - An array of repository objects. #### Response Example ```json { "repositories": [ { "id": "repo_id_1", "name": "repo-name-1", "default_branch": "main" }, { "id": "repo_id_2", "name": "repo-name-2", "default_branch": "develop" } ] } ``` ``` -------------------------------- ### Asynchronous Code Execution Example Source: https://docs.freestyle.sh/v2/vms An example demonstrating asynchronous code execution, likely within a JavaScript environment. It uses 'await' and 'vm.fs' which suggests interaction with a virtual machine's file system. ```javascript await vm.fs. ``` -------------------------------- ### VM Creation and Code Execution Source: https://docs.freestyle.sh/v2/vms Demonstrates the creation of a VM with JavaScript and Python environments and executes code in both. ```APIDOC ## POST /v2/vms ### Description Creates a new Virtual Machine (VM) with specified language runtimes and executes code within them. The first VM creation with a unique configuration might take longer due to environment building and caching. ### Method POST ### Endpoint /v2/vms ### Parameters #### Query Parameters None #### Request Body - **with** (object) - Required - Specifies the language runtimes to include in the VM. Example: `{ js: new VmNodeJs(), python: new VmPython() }` ### Request Example ```javascript import { VmPython } from "@freestyle-sh/with-python"; import { VmNodeJs } from "@freestyle-sh/with-node"; const { vm } = await freestyle.vms.create({ with: { js: new VmNodeJs(), python: new VmPython(), }, }); await vm.js.runCode(`console.log("Hello World!")`).then(console.log); await vm.python.runCode(`print("Hello World!")`).then(console.log); ``` ### Response #### Success Response (200) - **vm** (object) - The created VM instance, allowing code execution. - **vmId** (string) - The unique identifier for the created VM. - **domains** (array) - List of domains associated with the VM. - **consoleUrl** (string) - URL to access the VM's console. #### Response Example ```json { "vmId": "unique-vm-id", "vm": { ... }, "domains": ["example.com"], "consoleUrl": "https://console.freestyle.sh/vm-id" } ``` ``` -------------------------------- ### Resize VM Source: https://docs.freestyle.sh/v2/git Resizes a Virtual Machine. ```APIDOC ## POST /API-Reference/vm/resize_vm ### Description Resizes a Virtual Machine. ### Method POST ### Endpoint /API-Reference/vm/resize_vm ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body (Details not provided in the input text) ### Request Example (Example not provided in the input text) ### Response #### Success Response (200) (Details not provided in the input text) #### Response Example (Example not provided in the input text) ``` -------------------------------- ### Full OpenCode Setup with API Client Source: https://context7_llms Demonstrates a complete setup of OpenCode within a Freestyle VM, including exposing the web UI and creating an API client for session management and file operations. ```typescript import { freestyle, VmSpec } from "freestyle-sandboxes"; import { VmOpenCode } from "@freestyle-sh/with-opencode"; const { vm } = await freestyle.vms.create({ spec: new VmSpec({ with: { opencode: new VmOpenCode(), }, }), }); // Expose the web UI for browser access const { url } = await vm.opencode.routeWeb(); console.log(`Web UI: ${url}`); // Create an API client for programmatic access const { client } = await vm.opencode.client(); // Create a new coding session const session = await client.session.create({ path: "/workspace" }); // List files in the workspace const files = await client.path.get({}); console.log("Files:", files.data); ``` -------------------------------- ### Install Freestyle Serverless Deployments CLI Source: https://docs.freestyle.sh/v2/serverless/deployments Instructions for installing the Freestyle Serverless Deployments command-line interface (CLI) using different package managers. Choose the command that corresponds to your preferred package manager (npm, pnpm, yarn, or bun) to install the necessary tools. ```shell npm install freestyle-sandboxes@beta ``` ```shell pnpm add freestyle-sandboxes@beta ``` ```shell yarn add freestyle-sandboxes@beta ``` ```shell bun add freestyle-sandboxes@beta ```