---
name: codeengine-fun-create-inlinecode
title: Creating function workloads with inline code
description: You can create your function with inline code. Your code is stored with your function. You can create this type of function from the console or with the CLI.
last-updated: 2026-07-01
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/codeengine?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Creating function workloads with inline code
{: #fun-create-inlinecode}

You can create your function with inline code. Your code is stored with your function. You can create this type of function from the console or with the CLI.
{: shortdesc}

A code bundle is a collection of files that represents your function code. This code bundle is injected into the runtime container. Your code bundle is created by Code Engine and is stored in container registry or inline with the function. A code bundle is not a Open Container Initiative (OCI) standard container image.


## Creating a function with inline with the console
{: #fun-create-inline-console}

Create a function with inline code from the console.
{: shortdesc}

1. Open the [Code Engine](https://cloud.ibm.com/codeengine/overview){: external} console.
2. Select **Start creating**.
3. Select a project from the list of available projects. You can also [create a new one](https://cloud.ibm.com/docs/codeengine?topic=codeengine-manage-project&format=markdown#create-a-project). You must select a project to create a function.
4. Select **Function**.
5. Enter a name for the function; for example, `myfunction`. Use a name for your function that is unique within the project.
6. Select a **Runtime image** for your function code. For more information, see [Runtimes](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime&format=markdown).
7. Select to **Specify your code as an inline code bundle**. When you select this option, your function is created with a sample code bundle for the selected runtime. You can edit the sample code after the function is created. The code bundle is stored inline with the function.
8. Specify your resource information, including [CPU and memory combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-runtime&format=markdown#fun-supported-combo) and [Scale down delay](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-work&format=markdown#functions-scale).
9. Optionally, specify a [custom domain](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-domainmapping&format=markdown) or [environment variables](https://cloud.ibm.com/docs/codeengine?topic=codeengine-envvar&format=markdown). You can add these options later.
10. Click **Create**.
11. After the function status changes to **Ready**, you can test the function. Click **Test function** and then click **Send request**. To open the function in a web page, click **Function URL**.
12. You can also change your function code in the Editor window. When you redeploy your function, the code is stored inline.

You can invoke your function by clicking **Test function** and then **Send request**.

You can retrieve the code that was used to create any inline function by running the **`function get`** command with the `--save` options. For example, `ibmcloud ce function get --name myfunction
 --save hellofun2.js`.
{: tip}

## Creating a function with inline code with the CLI
{: #fun-create-inline-cli}

Create a function with inline code with the CLI by using the **`ibmcloud ce function create`** command. For a complete listing of options, see the [**`ibmcloud ce function create`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-create) command.
{: shortdesc}

Before you begin

* Set up your [Code Engine CLI](https://cloud.ibm.com/docs/codeengine?topic=codeengine-install-cli&format=markdown) environment.
* [Create and work with a project](https://cloud.ibm.com/docs/codeengine?topic=codeengine-manage-project&format=markdown).

This example uses a code file named `main.js`. You can use the following example code to create your `main.js` file or you can substitute your own code.

```javascript
/**
 * The `main` function is the entry-point into the function.
 * It has one optional argument, which carries all the
 * parameters the function was invoked with.
*/
async function main(params) {
  // log environment variables available to the function
  console.log(process.env);
  // log Code Engine system headers available to the function
  console.log(params.__ce_headers);
  // log all parameters for debugging purposes
  console.log("params: "+params);
  // since functions are invoked through http(s), we return an HTTP response
  return {
      statusCode: 200,
      headers: { 'Content-Type': 'application/json' },
      body: params };
}

// this step is necessary, if you gave your main function a different name
// we include it here for documentation purposes only
module.exports.main = main;
```
{: codeblock}


Create your function and include the code in the command. For example, use the [**`ibmcloud ce function create`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-create) command to create the `myhellofun` function.

```txt
ibmcloud ce fn create --name myhellofun --inline-code main.js --runtime nodejs
```
{: pre}


Example output

```txt
Creating function 'myhellofun'...
OK
Run 'ibmcloud ce function get -n myhellofun' to see more details.

https://myhellofun.glxo4kabcde.us-south.codeengine.appdomain.cloud
```
{: screen}

You can save the code that was used to create any inline function by running the **`function get`** command with the `--save` options. For example, `ibmcloud ce function get --name myhellofun --save hellofun2.js`.
{: tip}

## Next steps
{: #nextsteps-funinline}

- After your function is created, you can access your function by clicking **Test function** in the console or finding the URL for your function with the [**`function get`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-get) command.

- You can create a [custom domain mapping](https://cloud.ibm.com/docs/codeengine?topic=codeengine-domain-mappings&format=markdown) and assign it to your function.  

- After your function is created and deployed, you can update the function to meet your needs from the console or by using the [**`ibmcloud ce function update`**](https://cloud.ibm.com/docs/codeengine?topic=codeengine-cli&format=markdown#cli-function-update) command. If you want to update your source to use with your function, you must provide the `--build-source` option on the **`function update`** command.

After your function is created, you can update your function and its referenced code by using *any* of the following ways, independent of how you created or previously updated your function:

- If you have an existing code bundle, then you need to provide only a reference to the image, which points to the location of your container registry when you deploy your app. For more information, see [Creating function workloads from existing code bundles](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-existing&format=markdown).

    If you created your function by using the **`function create`** command and you specified the `--build-source` option to build the code bundle from local or repository source, and you want to change your function to point to a different code bundle, you must first remove the association of the build from your function. For example, run `ibmcloud ce function update -n FUN_NAME --build-clear`. After you remove the association of the build from your function, you can update the function to reference a different image. 
    {: note}

- If you are starting with source code that resides in a Git repository, you can choose to let Code Engine to build the code bundle from your source and create your function with a **single** operation. In this scenario, Code Engine uploads your code bundle to IBM Cloud&reg; Container Registry. To learn more, see [Creating your function from repository source code](https://cloud.ibm.com/docs/codeengine?topic=codeengine-fun-create-repo&format=markdown).

- If you are starting with source code that resides on a local workstation, you can choose for Code Engine to build the code bundle from your source and create your function with a **single** CLI command. In this scenario, Code Engine uploads your source code and code bundle to IBM Cloud&reg; Container Registry. 

    For example, you might choose for Code Engine to build your local source while you evolve the development of your source for the function. Then, after the code bundle is matured, you can update your function to reference the specific code bundle that you want. You can repeat this process as needed.



Looking for more code examples? Check out the [Samples for IBM Cloud Code Engine GitHub repo](https://github.com/IBM/CodeEngine){: external}.
{: tip}