In this guide, we will explain how to set up fully automatic Instagram posting using the Codex desktop app (from the creators of ChatGPT), an MCP server (Model Context Protocol), and the Undetectable anti-detect browser. The neural network will open the required profile by itself, go to the social network, upload an image, write the text, and click the “Publish” button.
Step-by-step guide: setting up automation from scratch
This automation setup is available even on the free version of the Undetectable browser! The main requirement is having an OpenAI subscription.
Step 1. Prepare the base and content
First, we need to prepare our stack:
1.Download the Undetectable anti-detect browser (automation is available even on the free version).
Important note: AI is an excellent executor, but the files need to be prepared for it in advance. Create a folder on your computer where you will put the ready images for posts and a document with texts. In the prompts, you will need to specify the exact path to these files.
How to find the file path?
- On Windows: Hold down the Shift key and right-click the file. In the menu that appears, select “Copy as path”. Note: when pasting the path into the prompt, it is better to remove the quotation marks around it.
- On macOS: Right-click the file, then hold down the Option (Alt) key. The “Copy” item will change to “Copy [File] as Pathname”. Click it.
Step 2. Launch Codex
Download the desktop Codex app from the official website and log in (as a reminder, an active OpenAI subscription is required).
Step 3. Connect the MCP server
Now we need to connect the neural network to the browser so it can control it. To do this, open a new chat in Codex and ask the AI to connect the MCP server.
Simply send the neural network the following prompt and attach the code snippet:
“Connect this MCP server:”
{ "mcpServers": { "undetectable-local-api-ts": { "command": "npx", "args": ["-y", "undetectable-local-api-mcp-ts"], "env": { "UNDETECTABLE_BASE_URL": "http://127.0.0.1:25325", "UNDETECTABLE_TIMEOUT": "60" } } }}The AI will understand everything and do it by itself. After it reports that the server has been added successfully, restart Codex and open the Undetectable browser so the changes take effect and the automation works correctly.
You can learn more about connecting the MCP server to other models on GitHub or NPM.
Instagram posting automation
When the technical part is ready, the most interesting part begins — writing the algorithm (prompt) for the AI. To show how the neural network logic works, we divided this process into two stages.
Stage 1: Test run
For the first test, we created a new chat in Codex and asked it to open a pre-configured profile in the anti-detect browser, go to Instagram, and create a post. We wrote the algorithm as if explaining the task to a real person: “find the plus button”, “click Next”, and so on.
Here is what our first prompt looked like:
Undetectable browser 1.Start the profile named "INSTA" using the start_profile tool
2.Wait 3 seconds for the browser to fully load
3.Navigate to https://www.instagram.com
4.Wait 3 seconds for the page to load
5.Look for the "+" (Create) icon and click it
6.A menu will appear — click "Post" from the menu options
7.Wait for the upload dialog to appear
8.Click the button "Select from computer"
9.A system file picker window will open
10.In the file picker, type or paste the full path:
(file path)
Then press Enter to confirm
11.Wait for the image to upload and appear in preview
12.Click the "Next" button (top right of the dialog) — this moves to crop/filter step
13.Click "Next" again — this moves to the caption step
14.Click on the caption text field
15.Type exactly the following text: (post text)
16.Click the "Share" button (top right)
17.Wait for the confirmation that the post was published
18.Take a screenshot to confirm success
Important: If the Instagram UI has been updated and buttons or menu items have different names or positions, adapt accordingly and proceed with the closest matching option to complete the task.
Result: It worked! The post was published. But the process took a lot of time. The AI made unnecessary movements, tried to visually find the right buttons, and imitated the human path click by click. We needed it to be faster.
Stage 2: AI optimizes itself
After the successful but slow task execution, we asked the neural network to analyze its actions and write a new optimized prompt for itself. The task was simple — take into account all the mistakes from the test run and make the automation as fast and reliable as possible.
Then we used the resulting prompt in a new Codex chat. As a result, the automation ran smoothly and without delays.
Start the Undetectable profile named Social UDT
Wait 3 seconds after profile start.
Connect to the profile’s returned websocket_link.
Open Instagram directly at:
https://www.instagram.com/create/select/
Wait 3 seconds for the create upload page.
If the Select from computer button is visible, click it and set this file in the chooser:
(Path to the image file)
If a file input is already present, set the same file directly on input[type="file"].
Wait up to 45 seconds for Instagram to finish upload/navigation.
Do not wait for Next buttons. The observed successful flow goes directly to:
https://www.instagram.com/create/details/
On the details page, fill the visible textarea:
textarea[aria-label="Write a caption…"]
with exactly:
(post text)
Find the enabled button whose exact visible text is Share.
Trigger the Share button directly with a full pointer/mouse/click event sequence on that button.
Wait up to 90 seconds for Instagram to leave /create/details/ and return to Instagram home or another non-create page.
Open:
https://www.instagram.com/undetectablebrowser/
Wait 5 seconds.
Take a screenshot confirming the newest grid item appears at the top-left of the profile grid.
Conclusion
The combination of MCP, Codex, and Undetectable completely changes the rules of the game in SMM and affiliate marketing. You are not just automating clicks — you are handing over profile management logic to AI.
Try setting up your first auto-post today!